Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1151974pxu; Fri, 27 Nov 2020 00:33:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCYJq7rMU3YidooO2Yjc2vgNZG/yRZWDB4X3qIVWqD+r7rdZgXhg9Ej+K+jp7GL+3GjUEo X-Received: by 2002:a50:e786:: with SMTP id b6mr6234860edn.242.1606466027263; Fri, 27 Nov 2020 00:33:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606466027; cv=none; d=google.com; s=arc-20160816; b=YMlqSIgpbVLbwmQaPzxfW+vBIzsh8U1XUzqvvhnGDThWgOX4DZtDcE9s2kt3GuqEs8 miChoFnv+tNC5CPPYCt6hF1dGMWJM1zfI0jHZN0zQ32GA0cTgNs8reoxCoZoryxLFvuk yrIpAGpOVHzae/3LJxoprp3QkNt1WGHSrs2Pqwel9OEZ366uD6iutxtdCQ7KN/zVjAHD 5eDqN+wgjpa7+s9uOPjz32fzHJhHN2BL0YYuSDlxljL9qDIDn/4Livq1ZlClxgK1vFL1 C6owsqqxT9RobirMEB1blCR44jxJdR/z8HdWQOzpIDzAq14J37/WEbFAfGKazCuUKe0q 20Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=x1+weTARWb/CYeVIMgbffPZozCU9l6YlWV0tin010xk=; b=BBU2tKCjIvyKRZ+KpoHL4fGSgH0MtTqO/g7jPOjIYCRqTLQS3yXeDlrIDXZ//USrcG G/wvuOs1cQ0/ac+hCAN5fBvBVJtkVrlupGEpx8qt9cKnv5mbeBUqDDnl3E4clflf+71t 8dmN9kkd/wpBdilGeAsjxXmVx/VYw8Bj30mBLE1Wys0E+ohxc6ItSRb1L0NJFksAiue8 RqziH6g3BBLH7m2TUTI6PPZCyKJS9IJ8hgG0HRSyuWxpJxtdts+F31LeS/MXOfEDkoOX QFAkTEPwwbpmiZkUAIJUCrkblCvBHBQebs+CJhXM9i7GkiFHdm6eoHC8p8QnV+cnE499 zx3A== 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 s3si4497164ejd.148.2020.11.27.00.33.24; Fri, 27 Nov 2020 00:33:47 -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 S2391103AbgKZOeJ (ORCPT + 99 others); Thu, 26 Nov 2020 09:34:09 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:7995 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389743AbgKZOeJ (ORCPT ); Thu, 26 Nov 2020 09:34:09 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4ChgHH1hXlzhhmV; Thu, 26 Nov 2020 22:33:47 +0800 (CST) Received: from huawei.com (10.175.113.25) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 22:33:56 +0800 From: Zheng Zengkai To: , , , CC: , , , Subject: [PATCH] tomoyo: Fix null pointer check Date: Thu, 26 Nov 2020 22:38:15 +0800 Message-ID: <20201126143815.67697-1-zhengzengkai@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since tomoyo_memory_ok() will check for null pointer returned by kzalloc() in tomoyo_assign_profile(), tomoyo_assign_namespace(), tomoyo_get_name() and tomoyo_commit_ok(), then emit OOM warnings if needed. And this is the expected behavior as informed by Tetsuo Handa. Let's add __GFP_NOWARN to kzalloc() in those related functions. Besides, to achieve this goal, remove the null check for entry right after kzalloc() in tomoyo_assign_namespace(). Fixes: 57c2590fb7fd ("TOMOYO: Update profile structure") Fixes: bd03a3e4c9a9 ("TOMOYO: Add policy namespace support.") Reported-by: Hulk Robot Suggested-by: Tetsuo Handa Signed-off-by: Zheng Zengkai --- security/tomoyo/common.c | 2 +- security/tomoyo/domain.c | 4 +--- security/tomoyo/memory.c | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) 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); diff --git a/security/tomoyo/memory.c b/security/tomoyo/memory.c index 2e7fcfa923c9..1b570bde7a3b 100644 --- a/security/tomoyo/memory.c +++ b/security/tomoyo/memory.c @@ -73,7 +73,7 @@ bool tomoyo_memory_ok(void *ptr) */ void *tomoyo_commit_ok(void *data, const unsigned int size) { - void *ptr = kzalloc(size, GFP_NOFS); + void *ptr = kzalloc(size, GFP_NOFS | __GFP_NOWARN); if (tomoyo_memory_ok(ptr)) { memmove(ptr, data, size); @@ -170,7 +170,7 @@ const struct tomoyo_path_info *tomoyo_get_name(const char *name) atomic_inc(&ptr->head.users); goto out; } - ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS); + ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS | __GFP_NOWARN); if (tomoyo_memory_ok(ptr)) { ptr->entry.name = ((char *) ptr) + sizeof(*ptr); memmove((char *) ptr->entry.name, name, len); -- 2.20.1