From patchwork Tue Mar 16 10:04:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12141647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37910C433E0 for ; Tue, 16 Mar 2021 10:04:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A527364FC0 for ; Tue, 16 Mar 2021 10:04:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A527364FC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 33F446B006C; Tue, 16 Mar 2021 06:04:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EF9A6B006E; Tue, 16 Mar 2021 06:04:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 190736B0070; Tue, 16 Mar 2021 06:04:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id ED5A06B006C for ; Tue, 16 Mar 2021 06:04:39 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B1C5D181AC217 for ; Tue, 16 Mar 2021 10:04:39 +0000 (UTC) X-FDA: 77925303078.16.3010355 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf04.hostedemail.com (Postfix) with ESMTP id 340B6132 for ; Tue, 16 Mar 2021 10:04:39 +0000 (UTC) Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lM6Yz-0005p6-G2; Tue, 16 Mar 2021 10:04:33 +0000 From: Colin King To: Andrew Morton , Minchan Kim , John Hubbard , Stephen Rothwell , Greg Kroah-Hartman , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: cma: Fix potential null dereference on pointer cma Date: Tue, 16 Mar 2021 10:04:33 +0000 Message-Id: <20210316100433.17665-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Stat-Signature: w5fs5ik86eid5i468jgxgzzun9aitkhd X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 340B6132 Received-SPF: none (canonical.com>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=youngberry.canonical.com; client-ip=91.189.89.112 X-HE-DKIM-Result: none/none X-HE-Tag: 1615889079-134326 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Colin Ian King At the start of the function there is a null pointer check on cma and then branch to error handling label 'out'. The subsequent call to cma_sysfs_fail_pages_count dereferences cma, hence there is a potential null pointer deference issue. Fix this by only calling cma_sysfs_fail_pages_count if cma is not null. Addresses-Coverity: ("Dereference after null check") Fixes: dc4764f7e9ac ("mm: cma: support sysfs") Signed-off-by: Colin Ian King Acked-by: Minchan Kim Reviewed-by: John Hubbard --- mm/cma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/cma.c b/mm/cma.c index 6d4dbafdb318..90e27458ddb7 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -512,7 +512,8 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, cma_sysfs_alloc_pages_count(cma, count); } else { count_vm_event(CMA_ALLOC_FAIL); - cma_sysfs_fail_pages_count(cma, count); + if (cma) + cma_sysfs_fail_pages_count(cma, count); } return page;