Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1411210ybj; Fri, 20 Sep 2019 10:01:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1ikr/xEKgKCf9sRU9Ry5z6Pqlcs0IpI045PGkO5qCzIxDMsGsyNPCgWD0gx4hso8/qa+H X-Received: by 2002:a5d:4611:: with SMTP id t17mr12804454wrq.135.1568998911744; Fri, 20 Sep 2019 10:01:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568998911; cv=none; d=google.com; s=arc-20160816; b=fWsDIKdqm7v/vY4f+yXzoxsWJlkQ0Bs44NCvVKBu16VSfpF1JWrAGSEpOK6d4F4tW5 ZTRKchLSXaUFhV9yFETm1NpoVqdQ/N4mS8FAgAq9ZHBl7E1SuuhyvmfcA215P+XBt5dD SMg56CtejPLLSUltMOHy+A+poEU2cOckeKSM703d9nNfgH3j9PZnwFIjbKTeC7TKucWz DF0R+KNur0cnrJ5q94OUMH6HR2DWxcwwv7XHzcaix30+SAMZ1qbeiNFedWLomaJChf3h XMZYAMLrZw/zHD8umeSlAqGyfGIECVYVnoRto1axdvLsv7184bHkQY7QbgN3qRBZJzLC ZKZw== 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=fLReVEU3cNJh5RMufazJxBApXNGZ7MW3Izh0vJu592k=; b=MO9lxG02b5WM7FHIi9v+3c2SaL81jN5hZo6hPgoYFcTaxe4pv/naeubG45Xkv+d7Eu smLwDbhqGOobRfdVfkpVADtjQwPAVYOg0HhwU1DDM1NwYaruMzinNIJS+vWPVvmbeK4w Aes365d6eMJ4jZ8tmjs4vw3RSy9qfvwvsrJXwwpxGsABl7udmAk0zbHn8i19Ck+auSkE hFCYSOhHgfTCs27NtVUsWECCsWv2xbx9glPul7FGAGjOp4+TQXdsgDUMiS2HcWRS41Dg yABEE9jZJcpaoijAF7cU8JVuNrqN4G4EnLqWp6rttLSIioaQaAyhv5P9oI76QuVR1TBF w8lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C4EWCyGC; 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 b15si1659378edm.395.2019.09.20.10.01.27; Fri, 20 Sep 2019 10:01:51 -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=C4EWCyGC; 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 S2408204AbfITGEc (ORCPT + 99 others); Fri, 20 Sep 2019 02:04:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:46036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408197AbfITGEc (ORCPT ); Fri, 20 Sep 2019 02:04:32 -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 B14812086A; Fri, 20 Sep 2019 06:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568959471; bh=FMHYLNhnUIWX/Ad7Hx9zHh7rSIMaDyP2houL0wEpfnY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C4EWCyGCf0Pe4SOOTvruW2VA7hJDuNTJQvwqSPAm8TeTTyPgb3NzE2UD/Vxx7hhH8 5EvAoib85g/KwuzD4n4t55sirjnnO++lnuM/bVmIL9LJJ1O91OHOmwZxErmI1YOWFR DUfktYSjkx6Ez0rYZ583u/BoyYnuLjiqAS6Dauy0= Date: Fri, 20 Sep 2019 08:04:26 +0200 From: Greg KH To: Nicolas Pitre Cc: Xiaoming Ni , penberg@cs.helsinki.fi, jslaby@suse.com, textshell@uchuujin.de, sam@ravnborg.org, daniel.vetter@ffwll.ch, mpatocka@redhat.com, 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 Message-ID: <20190920060426.GA473496@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 Thu, Sep 19, 2019 at 10:56:15PM -0400, Nicolas Pitre wrote: > 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" :( > > Something probably needs to be "communicated" about that. I know, but it's also kind of fun to see what these "automated" checkers find, sometimes the resulting patches almost work properly :) This one is really close, I think if the likely/unlikely gets cleaned up, it is viable. > > > 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? > > This is maybe too subtle a fact. The "communication" could be done with > some GFP_WONTFAIL flag, and have the allocator simply pannic() if it > ever fails. That's a good idea to do as well. thanks, greg k-h