Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp419154pxu; Thu, 26 Nov 2020 01:59:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjgGzn37+CHI1JFv9Ha5HX3+dlLvP7rTjeEBJ4pAx1oj8PyCUhOjSiRak4LXB5/R1TU2sd X-Received: by 2002:a05:6402:17b4:: with SMTP id j20mr1775485edy.24.1606384746810; Thu, 26 Nov 2020 01:59:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606384746; cv=none; d=google.com; s=arc-20160816; b=Fa+Mb9QKWp1ngPutImTnaTcRT2EIleq6c8AKKXkOrQDSae7MmIDlwqedjNwaJcKNcG Gk7vUnrHuE8rwB3DLUBUzinPJGlf83INYyzSGTroZ4NEFAuM4Z6IIgIu+jk/t2wEGKu1 1Dqy8TvF52NSJNmtCINUxWu51Krf1Q5Xt9Tec2wVUmx9OlBvVn4rHIpeBlFHDzV+yR+C Lr5+ArGB5tfdRinK2Op8+Frc7p8Xi0Uu4MqJsL6/H6VVyB/5mwx53yOuM1godm0lCNFT xdDWqJ7eTp9XEjKh3N5QmHv/Hm340x7h/5VLdzDrerYg2MmyqGczQulhBoXomac86lZh Hm2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=Nt0zYYDszp91Tz7U0zUwntw2CIseTDlnpN8kN2r1e5M=; b=e2f580jI0KdbU1q/63C/0WjHHAvLAdtUkjvDvJ7zu5Avu6RH6OzOu/cR/IlArn49hh rAzUWQgX6fqgur9cXRIb+MyvZuv7Hpt7oYofFPUn2CvOu75fK5YfEaIxhraMd1+KQTCc DPhBnp6LB3CjyLBzzj7ik0w4Wd+jLdmkkPa0T/0Z7wbnXGDoqb5vSeo/WdSKteBxo4wF mFk9dDDbgrT0K9FPV+wyCYyGknK/uLsV3EJ663dZIeDSNznuXGjO3hI3FzRukL/vVj+a PhsCyiADSQXIL9orB4RBttl/QV7cIU8FTv55bmb3s8D/dhb6h6/F6dXpH4sNWpNrET0j 84yQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr21si1196129ejc.446.2020.11.26.01.58.44; Thu, 26 Nov 2020 01:59:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388090AbgKZGeM (ORCPT + 99 others); Thu, 26 Nov 2020 01:34:12 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8403 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732690AbgKZGeM (ORCPT ); Thu, 26 Nov 2020 01:34:12 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4ChSdN3y5Sz73qx; Thu, 26 Nov 2020 14:33:44 +0800 (CST) Received: from [10.174.178.154] (10.174.178.154) by smtp.huawei.com (10.3.19.205) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 26 Nov 2020 14:33:56 +0800 Subject: Re: [PATCH] tomoyo: Avoid potential null pointer access To: Tetsuo Handa CC: , , , , References: <20201125121043.107662-1-zhengzengkai@huawei.com> From: Zheng Zengkai Message-ID: <01d29bbf-9d77-c787-b2c2-d88a6a5047f7@huawei.com> Date: Thu, 26 Nov 2020 14:33:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.154] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Tetsuo Got it , Thank you for your explanation. > Hello, Zheng. > > Thank you for a patch, but I won't apply this patch. > Expected behavior is that tomoyo_warn_oom() is called > if tomoyo_memory_ok() is called with entry == NULL. > > Adding __GFP_NOWARN might be OK, but returning without tomoyo_warn_oom() is NG. > > On 2020/11/25 21:10, Zheng Zengkai wrote: >> Calls to kzalloc() should be null-checked in order to avoid >> any potential failures or unnecessary code execution. >> Fix this by adding null checks for _entry_ right after allocation. >> >> Fixes: 57c2590fb7fd ("TOMOYO: Update profile structure") >> Reported-by: Hulk Robot >> Signed-off-by: Zheng Zengkai > Nacked-by: Tetsuo Handa As your say,  I found the function tomoyo_assign_namespace( ) in security/tomoyo/domain.c has the similar situation, Can I add __GFP_NOWARN for both and remove the null check for _entry_ in tomoyo_assign_namespace( )? diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index 4bee32bfe16d..bc54d3c8c70a 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c @@ -498,7 +498,7 @@ static struct tomoyo_profile *tomoyo_assign_profile         ptr = ns->profile_ptr[profile];         if (ptr)                 return ptr; -       entry = kzalloc(sizeof(*entry), GFP_NOFS); +       entry = kzalloc(sizeof(*entry), GFP_NOFS | __GFP_NOWARN);         if (mutex_lock_interruptible(&tomoyo_policy_lock))                 goto out;         ptr = ns->profile_ptr[profile]; diff --git a/security/tomoyo/domain.c b/security/tomoyo/domain.c index dc4ecc0b2038..c6e5cc5cc7cd 100644 --- a/security/tomoyo/domain.c +++ b/security/tomoyo/domain.c @@ -473,9 +473,7 @@ struct tomoyo_policy_namespace *tomoyo_assign_namespace(const char *domainname)                 return ptr;         if (len >= TOMOYO_EXEC_TMPSIZE - 10 || !tomoyo_domain_def(domainname))                 return NULL; -       entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS); -       if (!entry) -               return NULL; +       entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS | __GFP_NOWARN);         if (mutex_lock_interruptible(&tomoyo_policy_lock))                 goto out;         ptr = tomoyo_find_namespace(domainname, len); >> --- >> security/tomoyo/common.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c >> index 4bee32bfe16d..99b4fafcb100 100644 >> --- a/security/tomoyo/common.c >> +++ b/security/tomoyo/common.c >> @@ -499,6 +499,8 @@ static struct tomoyo_profile *tomoyo_assign_profile >> if (ptr) >> return ptr; >> entry = kzalloc(sizeof(*entry), GFP_NOFS); >> + if (!entry) >> + return NULL; >> if (mutex_lock_interruptible(&tomoyo_policy_lock)) >> goto out; >> ptr = ns->profile_ptr[profile]; >> > . >