Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1413330ybj; Fri, 20 Sep 2019 10:03:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3CIvlKAuQ09vCbq81oWin8wHXp2Zxb4pJ5KltwFA7SKV1+2u23vzJJ4LKWSlgXeWtlUKC X-Received: by 2002:a17:906:d8a9:: with SMTP id qc9mr18807021ejb.199.1568999012512; Fri, 20 Sep 2019 10:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568999012; cv=none; d=google.com; s=arc-20160816; b=uldzktc6FJVpX2BxwjY0Iie3ZSNaoKQZTtxNXlzDaZgT98eARpekIbcoNz/TyfmUtN H/F1Twtp6yUKyTjEB0x+0VXJrREYGlcKv9Skg5kHn7teooDJnRSh6PzDpQQClmCPQC3s FZf0RtkE/UCwHajgsSbeDgKKx7KCcp0bQyrqdIZt1vC1IM5EwA+z/U+590d0J0xsAToK NW5OF1G2rPlOkHenz8IopFjWVmAv36OtudmoqOhM8KCsfmXPwqkaMlz1iqNHF6eghsLw hfZV2iwppO3VbzVftOSmAN3+gFa2qVCrh+u0v0T/KN37TWyJjPNmVpwI9q6XDLELlHDi ltgw== 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=653FOjC6ArqY/pbeQYgHq6X+cOu9ak6+CYvDI5qZNbE=; b=FaiVrX00YBcpQtKI4uDp2hGhp2hv5+PiIZDUd7TuarMTqXnKjmsC+9QGa6KgQTM4sA 6mm+l5eAMKFRMQSDPZDOsgq9G6NHQB2kCWB/E++XyE9fSvO2l/4enoDWb84R+nhOIf1W X7a3rwIXUVNDi/x8bgoNoxZJrB2t8P+iarRlQviZoRj/KpLCnRN+M7ONlmI17bv2F647 DJIptzRP4ww6yxzF9VDzsYsB2DFuredqPqJKKPRoTO2L9Q97jzLg2//9yunET9u74k0e Yb6rHz8UGgBwhiWiiPnpPMkRF4eOc6dreKdYQcsaKDNmPvKAZmZsfAfSTmrn5hhcWtuB cw7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Oi+BknRY; 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 l21si1780170edc.112.2019.09.20.10.03.08; Fri, 20 Sep 2019 10:03:32 -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=Oi+BknRY; 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 S2408238AbfITGF0 (ORCPT + 99 others); Fri, 20 Sep 2019 02:05:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408232AbfITGF0 (ORCPT ); Fri, 20 Sep 2019 02:05:26 -0400 Received: from localhost (unknown [145.15.244.23]) (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 A179D20882; Fri, 20 Sep 2019 06:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568959525; bh=X7t/VZSp6LudvbPeX6l74ReA7A/d8L11/pSeOs2po1A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Oi+BknRY202JsDjyAQXI0SXV4CWWmY1cnDooz/gwqyHNCYimNCZANRM+89t7UTpcp uKwuE6Egkbqu/yPTj3mQa63LQCMSCXzzb1v9//VKXBL1UvoMUZ/C9VQIronA6ODsWq QKaIUW/AUYezFpHJXtfpDb5IWkfEKhW3NPnbuwJg= Date: Fri, 20 Sep 2019 08:04:54 +0200 From: Greg KH To: Nixiaoming Cc: "penberg@cs.helsinki.fi" , "jslaby@suse.com" , "nico@fluxnic.net" , "textshell@uchuujin.de" , "sam@ravnborg.org" , "daniel.vetter@ffwll.ch" , "mpatocka@redhat.com" , "ghalat@redhat.com" , "linux-kernel@vger.kernel.org" , Yangyingliang , yuehaibing , Zengweilin Subject: Re: [PATCH] tty:vt: Add check the return value of kzalloc to avoid oops Message-ID: <20190920060454.GB473496@kroah.com> References: <1568884695-56789-1-git-send-email-nixiaoming@huawei.com> <20190919092933.GA2684163@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 20, 2019 at 02:29:49AM +0000, Nixiaoming wrote: > On 2019/9/19 17:30, 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? > > I did not actually observe the null pointer here. > I am confused when I see the code allocated here without check the return value. > Small memory allocation failures are difficult to occur during system initialization > But is it not safe enough if the code is not judged? > Also if the memory allocation failure is not allowed here, is it better to add the __GFP_NOFAIL flags? See my response to Nicolas, but yes, that would be a good way to handle this. thanks, greg k-h