Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp2839307ybj; Mon, 23 Sep 2019 10:14:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJWdrQLTxtWJWsAc23B34hysTamq0ShUpHt2jHZA+qUvPzYF4alO9S5kYBpgdly0zSbPvY X-Received: by 2002:a17:906:1e0e:: with SMTP id g14mr797471ejj.247.1569258860314; Mon, 23 Sep 2019 10:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569258860; cv=none; d=google.com; s=arc-20160816; b=l5LLWAgFoXBpOkJLCHAHUxBBulUhTz7IlA2WyPpHWaRAan35oCDfLGS/a7luVYfU4L 4n5hOvJ/maO4XIADfOCA0bjPIVB634MoiipfTbmgjpFyfNZyEAUUJlZ5O1kPZm81YjHg rPcUa2aP/p0NxUOtTyq+CWHJnoi/4oV61FpaRG66C+Y8QgGbB1H3J5ACL/+UUKnFqx6/ W5BZhmU4+ZP56orXRjcuw85xhFY2ffIBVsBIWYsxAZLUTRqFt218UrTZMaF0L8Nij4RU M8+ujW8Eky4L5DRuT/THSik1JAqq/8GeTvkkZIY7doO7EY7xjEbugrEbev+51nBk9bRl pm6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=ZIjgRDFNdiSMBqQjo3/LpUO8Zixf5ytPa6Ln6R4VTgE=; b=yIKnSCaKPpqkHCXrHAwFqkBmcSnXI07xPZxEPqbfiDvQJys7UGg4iSnlSX+1YyVuER oo7lhr8MjkVMDZfGPoZmpsHsja+sn5xnci4YNEIooCyjeK+Y65h50UNUNGYJXTpePzQy SOzaftl+0KRqcIpOgE1EmC14xLM5jehjuJvc4ibfoh4UVJE7y7upKsIioQmV5yLZ0/p/ NC1/Bht7gQ8+oQ7kKiwSPnLfrEJTohYrqBW/DBBMcFn98SWIVQiZhtelUu53OzVIFkXp d4y8W/zZjqy+KaPXIJThicBNfAMiURWbI+i2h7kzZqafHQue/8Z9+fm1311/0itlWYuz t62Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si6867575edb.7.2019.09.23.10.13.55; Mon, 23 Sep 2019 10:14:20 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731086AbfIUH0x (ORCPT + 99 others); Sat, 21 Sep 2019 03:26:53 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:45204 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731071AbfIUH0x (ORCPT ); Sat, 21 Sep 2019 03:26:53 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2127DC7C5191A21989DE; Sat, 21 Sep 2019 15:26:46 +0800 (CST) Received: from [127.0.0.1] (10.57.88.168) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Sat, 21 Sep 2019 15:26:39 +0800 Subject: Re: [PATCH] tty:vt: Add check the return value of kzalloc to avoid oops To: Greg KH , Nicolas Pitre CC: , , , , , , , , , , References: <1568884695-56789-1-git-send-email-nixiaoming@huawei.com> <20190919092933.GA2684163@kroah.com> <20190920060426.GA473496@kroah.com> From: Xiaoming Ni Message-ID: Date: Sat, 21 Sep 2019 15:26:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190920060426.GA473496@kroah.com> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.57.88.168] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/9/20 14:04, Greg KH wrote: > 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 > > . > Thank you for your advice. @ Nicolas Pitre Can I make a v2 patch based on your advice ? Or you will submit a patch for "GFP_WONTFAIL" yourself ? thanks Xiaoming Ni