Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp68617ybj; Thu, 19 Sep 2019 10:49:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjUAwPTo3XcL67xxZADijwQ4EuB1UaeB4kjxxp3FxdL+lRBbaY3457X59+ur6x+u5vMt7r X-Received: by 2002:aa7:c98a:: with SMTP id c10mr17880325edt.23.1568915344662; Thu, 19 Sep 2019 10:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568915344; cv=none; d=google.com; s=arc-20160816; b=WhQttPmP2nkQ3G81qoy1moICmxjoazujgdvo55G2mY/GxNMJvyElVTJRVcemXtJEF0 AkkUA58ob/LkiOrU4Epz8THg5EABy5+0Svshzlf4YtoF5SBiRJw40LIco7B7YzhOTRiX Z6OvmytFarwZbbIAd1w9B0sL8B69KsMoSaeHrJ4ILt/T0Gn8xIM6FRZgkL01qm4HzdZO riQx/0eDKtWg6qNLHXvjJjrDVru/rw94vttjHyNg/esOfXbhFRe6dL6lx+eaHm2pVNXq X2+zEHsMcom6JQWvx3YdW9T3ltWhEzH8lsk6I/YCEdJJNYr77FrBJz9v9s9H9xOE2Wlf g9jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=bd1pxtlUmZ+v/tueqAxSnGiVLsMOHABAf1q350WcZyw=; b=f4nvDkbO2eOxTn4UKZvus1+EqrPCR4F7dXm80MNriAqMtzVEb9kJxJKYTUghGpdDKq 4BxBiS1Qi+8ibkX+TNDqtD4sW5iD2lPXHguYDsGXBA3Fd+drYqo+UmSNUDqio9XV/yvW 9VRMLoo7lqzGr3PgaoY7yGqq+Hic9kQ6wtz3iOv7byKXv63gDmHBR06IKfw6ZzvisxK+ VbywsXnNiSAimphz84KEzctdrbB6UIFFkS2LM6DZHb1YF1kc2g+f8Akd8oi9bQE8TTB1 +8gymWUli4ioVqb4fYCrKxCvT5uWlpXuCYxDBQq+9r9rgmgL69zLil4LlYmxaAIEBo7I 0JsA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si4819145ejk.327.2019.09.19.10.48.40; Thu, 19 Sep 2019 10:49:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391160AbfISPQW (ORCPT + 99 others); Thu, 19 Sep 2019 11:16:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41600 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388706AbfISPQW (ORCPT ); Thu, 19 Sep 2019 11:16:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9811780F6D; Thu, 19 Sep 2019 15:16:20 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF4625C226; Thu, 19 Sep 2019 15:16:19 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id x8JFGJuJ015086; Thu, 19 Sep 2019 11:16:19 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id x8JFGHsn015068; Thu, 19 Sep 2019 11:16:17 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Thu, 19 Sep 2019 11:16:17 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Greg KH cc: Xiaoming Ni , penberg@cs.helsinki.fi, jslaby@suse.com, nico@fluxnic.net, textshell@uchuujin.de, sam@ravnborg.org, daniel.vetter@ffwll.ch, ghalat@redhat.com, linux-kernel@vger.kernel.org, yangyingliang@huawei.com, yuehaibing@huawei.com, zengweilin@huawei.com Subject: Re: [PATCH] tty:vt: Add check the return value of kzalloc to avoid oops In-Reply-To: <20190919092933.GA2684163@kroah.com> Message-ID: References: <1568884695-56789-1-git-send-email-nixiaoming@huawei.com> <20190919092933.GA2684163@kroah.com> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 19 Sep 2019 15:16:21 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 19 Sep 2019, Greg KH wrote: > On Thu, Sep 19, 2019 at 05:18:15PM +0800, Xiaoming Ni wrote: > > Using kzalloc() to allocate memory in function con_init(), but not > > checking the return value, there is a risk of null pointer references > > oops. > > > > Signed-off-by: Xiaoming Ni > > We keep having this be "reported" :( > > > --- > > drivers/tty/vt/vt.c | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c > > index 34aa39d..db83e52 100644 > > --- a/drivers/tty/vt/vt.c > > +++ b/drivers/tty/vt/vt.c > > @@ -3357,15 +3357,33 @@ static int __init con_init(void) > > > > for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { > > vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); > > + if (unlikely(!vc)) { > > + pr_warn("%s:failed to allocate memory for the %u vc\n", > > + __func__, currcons); > > + break; > > + } > > At init, this really can not happen. Have you see it ever happen? > > > INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); > > tty_port_init(&vc->port); > > visual_init(vc, currcons, 1); > > vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); > > + if (unlikely(!vc->vc_screenbuf)) { > > Never use likely/unlikely unless you can actually measure the speed > difference. For something like this, the compiler will always get it > right without you having to do anything. > > And again, how can this fail? Have you seen it fail? > > > + pr_warn("%s:failed to allocate memory for the %u vc_screenbuf\n", > > + __func__, currcons); > > + visual_deinit(vc); > > + tty_port_destroy(&vc->port); > > + kfree(vc); > > + vc_cons[currcons].d = NULL; > > + break; > > + } > > vc_init(vc, vc->vc_rows, vc->vc_cols, > > currcons || !vc->vc_sw->con_save_screen); > > } > > currcons = fg_console = 0; > > master_display_fg = vc = vc_cons[currcons].d; > > + if (unlikely(!vc)) { > > Again, never use likely/unlikely unless you can measure it. > > thanks, > > greg k-h Why does it use GFP_NOWAIT and not GFP_KERNEL? Is there some problem with GFP_KERNEL during initialization? Mikulas