Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1105417ybm; Wed, 22 May 2019 17:36:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTh6zMKFqyj7fUKSsr/HxlTFoUb86Ll27t3mkzdkRXssCMV7+ij0pc/9Ra/QjSdySQpUU3 X-Received: by 2002:a62:6341:: with SMTP id x62mr98452785pfb.63.1558571806002; Wed, 22 May 2019 17:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558571805; cv=none; d=google.com; s=arc-20160816; b=ctecgKtOAWfi+ZomaWU3KI9BmOykLcAsgEYs40cTz8W10+oCzsTsDbolP7P3V1PN12 sj7jzCcZ70Z3h/gjKe+UAkafMmntZHfcdUzRMeeDyCF/z7cjzbWjS0YhR6Nc4lgbDX4R PJWCBFOT+PKr7/B9Fu4qkuZHQkbZ79s5n8LCWGjioz4k/OsI1L2F0H1Ky5fcHn65kCBK 5S9hPxGNc1q+BpOZL6t8kReT0gZoTzstA/XQs7v11jYOywoq3wYWZb4IEKatSGyPvdn8 ORPeljUNMlgqyAUYsQEgK08AhDCNm9OCWMA9uqA7MuirGKt8zwcZOGNv8Lv6IQufz9BC kNJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5JdUm2l2J0nCnS+Im0smPlNxmaAWXWEhfMhOXXEzL2A=; b=asa7+KW0g59fNTTtypBaxJhoyBu/JRQOckef6QcN8wuT/3A0ihvMcVp5nXs8ZQmiqZ 4xIl4bOgHpm3Acb+6JbznbNoDHGUR0pc48EhFp4QisdeMCMlI7DxtsmpNl500a6b5V3E qZTgqwrQktYbXut7somLj6SDrNgKEJnO8LHJcZsnomUt9OKm3LInst66jZTYtmzO3jmh 82iV0fyaGoXssT90Dx+CxdcihivS2fPEC2CiOGSJi1iZUEYGumc2WuYTrSFoLgCoR3th 9UdtCCNpL9MC5WVkrHaBbcnOuID2ve9KTv2ds+Baf1Nx2r/6Mw74bJ1pDOrCjmJgn31p +aMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="tdD/TwAn"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si27800035pfh.215.2019.05.22.17.36.30; Wed, 22 May 2019 17:36:45 -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=@gmail.com header.s=20161025 header.b="tdD/TwAn"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbfEWAfF (ORCPT + 99 others); Wed, 22 May 2019 20:35:05 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35942 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727691AbfEWAfE (ORCPT ); Wed, 22 May 2019 20:35:04 -0400 Received: by mail-pf1-f196.google.com with SMTP id v80so2219214pfa.3 for ; Wed, 22 May 2019 17:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5JdUm2l2J0nCnS+Im0smPlNxmaAWXWEhfMhOXXEzL2A=; b=tdD/TwAniWVHAhadj6ugXUkpEST28d+VKlQXMQrFV5gpA8rEWtIs8RKzEgC3+hiQJJ E1kYTqViIG2hW4QHl4NZ+kWTn5te5FI6S/U5LDFhH5su+NLfdSHKG7k605HsArFlGldF yYRlqO3y50cvIef3Gcx4QHL7fq5mkPEXDqbGvGtM0Tz+cy5pVjocVftO6DreKFdXDCKc uOOHvTKu/j6tlTqBTa+dNM5H76h5ccccPBYpZLzqs8qGCECc3O3yxBUDazcgYu5XF5jQ fS/2BHC4ciFlgu6QKcXedoA9V/tXigsV5xFM6KtkPbWEer7qisfJJKPKQboYXYz9qT7+ /wuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5JdUm2l2J0nCnS+Im0smPlNxmaAWXWEhfMhOXXEzL2A=; b=CZt4Tzj7Jfq451OcJHaHWSzWJUMoKBlo586vE7duk+lUZDh5/mgGoTQFFFrEP1AcYB UwtvM/DOIrnlAB0mMuDYf3gF2u9nF8Q9rsw0HVTJBKFkyNfotVNiqCFX5Gz9EiKChwN0 IrNlcRWnbMrFEqQF53k53Jl3ZvCrFb2Xu9yH1JdhGOr0eu/fmQB4NcCBh6EWi/LmBiKy D8C2rPVP6e3aw2l46arF5tZE9U2ggC2reDyVhvxc/Iic+0ESv8GVM9m0xiruDVAm/1vm qojurexS2KwLyCDaF3jJQyxnZeE+y9A64Xb3VJcr0p9JVsdqgGcEzztjhsPafxYqUniW WtKA== X-Gm-Message-State: APjAAAUXVGe5XLAXT6nZRqvRbR0TAJ/PmmZiR0uYBsENH3lCid6B2OJy MGzIA/I+2Nt1PVWrfJUaPTk/7LGSwv1nTA== X-Received: by 2002:a62:2e46:: with SMTP id u67mr100660401pfu.206.1558571703912; Wed, 22 May 2019 17:35:03 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id 63sm36845105pfu.95.2019.05.22.17.34.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 17:35:03 -0700 (PDT) Date: Thu, 23 May 2019 08:34:52 +0800 From: Gen Zhang To: Kees Cook , jslaby@suse.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2] consolemap: Fix a memory leaking bug in drivers/tty/vt/consolemap.c Message-ID: <20190523003452.GB14060@zhanggen-UX430UQ> References: <20190521092935.GA2297@zhanggen-UX430UQ> <201905211342.DE554F0D@keescook> <20190522015055.GC4093@zhanggen-UX430UQ> <201905221353.AD8E585E6D@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201905221353.AD8E585E6D@keescook> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c index b28aa0d..79fcc96 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) */ } ---