Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2010539ybm; Thu, 23 May 2019 09:56:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwV7dGKuIgLZA2e1LI0KadOQEz9+Tm0F/Lcz5YLrgb9BPBLdDCVCt5AQNT3gZKtG/6xNdMA X-Received: by 2002:a63:d4c:: with SMTP id 12mr86327201pgn.30.1558630604821; Thu, 23 May 2019 09:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558630604; cv=none; d=google.com; s=arc-20160816; b=QyzRb5YD10X1pzZVL7cuk+A2PHkxN3nqPaBQRzvJcg8gritHwnF8qcEAmAGMJJ5F0C V3ENXKYAk3QSxo0cWF5a6ffP1ot7nFXSJPoSlGhwzsLNqP949vnUXYeHvwOQBseJ4UUV DNLES8b/L9q4cp5FwAhpB2Ay9gkMk53gLw5TAGebMiyi+MrmsouG9D0dxXgK2xTu6U// aMvwtnNMgl6SQXGc0lK+VsofsuVnA7oIlDLxAdTOytD+OIdP3J2FsAIsMLrrV3AQeaoi Fs3Tli6AGCfiobVPLq2CSmjew0KUhNQiwFcrsoN3ymAy8q9Bu72oEm/H0ZzbqAwmwSiv D1mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=jM8bPKPXf1vLmOMB9nivq9wEiQ5oNGIfwZnpi/tQ11U=; b=pQL7Shgo9bvIhBtq0l8pLG4EKr+0pMFWIFdJhLmj1I3DfTc5gc6SjI94gSQFG/8daP ajaxhp5Yc6UnwDBzaPj5mH4HUEPlIGi66RqZcoyUzQlFXRQ60q/albyALe3qmh+TTSxU NWu1Q0oQCfv11pZqLOQwJ+GKLl67ft1AsZ2IBs8yFPvDq1ur+sgQM+YAxjhcBMYF6yBb nCT/I+taONXsNMmw74/2vxsITSAOUsIwrRN4mh4GwHHaOkZopjnIvmgldb4+vVhSjIrd Ui1UE0rmGoofx5I1UR9DlFc4drIzQWmCiNX5e+n7gG1BfxqSAdQrWUUCWVSz4B3u3HaF XubQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hxKU6VAp; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4si1445675pju.48.2019.05.23.09.56.29; Thu, 23 May 2019 09:56:44 -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=@chromium.org header.s=google header.b=hxKU6VAp; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731042AbfEWQyV (ORCPT + 99 others); Thu, 23 May 2019 12:54:21 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44811 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730790AbfEWQyV (ORCPT ); Thu, 23 May 2019 12:54:21 -0400 Received: by mail-pl1-f196.google.com with SMTP id c5so2987602pll.11 for ; Thu, 23 May 2019 09:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jM8bPKPXf1vLmOMB9nivq9wEiQ5oNGIfwZnpi/tQ11U=; b=hxKU6VApctxuI6bY6dYjsrprnDeMIP5e7X4grbMLeGrGi3OgFXCRTAvDudT5aCEu7R WMXgnhfgBFoB9zpZTXOT9ElzzM/QqVXsv2qnmehpgJG/rWXdqWGAGGJOOLHkRLslDqo8 syWoZcRKYdiPgfOwl6Q61f5V18hSqp9CEnRNM= 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; bh=jM8bPKPXf1vLmOMB9nivq9wEiQ5oNGIfwZnpi/tQ11U=; b=eR8c7ao7hamse3tPQgpYLRu8sxI97TVrbQMi/NdsrIRQk1muhaklZEZTZcoQRhQF4p hiG0yw/qxYS3YPwtJJJD9AEeWrTxOEBW3C8Xsr1W2xLKawOvsSs+fDSrH306EQ0IOLi9 UHacaLixo9oeK5SlKjxE7C6yxX1qzjFx6hcxY+MkmOPjYnG9cJLO0bisCZBGbwvtThS0 Dsrfq3fj+OPe8IrGa9o19K2IFKKOSGN2I5aFAdO8tgb5uF91ljFsRla04B8uvXITwY/9 ntPWL9Pt1o39UmItEZIl09jnsRzPOlPoLcxtdqtwJrNA0hBojM4yB6btd2kimJf/75Ok zi0g== X-Gm-Message-State: APjAAAVpXK9SNhFH73gRWm414Miw4YY9vhBlwK6J317Pf6Q3pcIdk/NO gD+gjsaYi8+MZkxRmrvLTfjxnA== X-Received: by 2002:a17:902:c01:: with SMTP id 1mr59795146pls.142.1558630460533; Thu, 23 May 2019 09:54:20 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y7sm1368984pge.89.2019.05.23.09.54.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 May 2019 09:54:19 -0700 (PDT) Date: Thu, 23 May 2019 09:54:18 -0700 From: Kees Cook To: Gen Zhang , Greg KH Cc: jslaby@suse.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] consolemap: Fix a memory leaking bug in drivers/tty/vt/consolemap.c Message-ID: <201905230952.B47ADA17A@keescook> References: <20190521092935.GA2297@zhanggen-UX430UQ> <201905211342.DE554F0D@keescook> <20190522015055.GC4093@zhanggen-UX430UQ> <201905221353.AD8E585E6D@keescook> <20190523003452.GB14060@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190523003452.GB14060@zhanggen-UX430UQ> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 08:34:52AM +0800, Gen Zhang wrote: > 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 As far as I can see this is correct, as it's just restoring the prior state before the p1 allocation. Reviewed-by: Kees Cook > --- > 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) */ > } > > --- -- Kees Cook