From mboxrd@z Thu Jan 1 00:00:00 1970 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=unavailable 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 3679AC433E9 for ; Tue, 16 Mar 2021 10:05:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8E9F65018 for ; Tue, 16 Mar 2021 10:05:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236244AbhCPKEp (ORCPT ); Tue, 16 Mar 2021 06:04:45 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:40942 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236203AbhCPKEk (ORCPT ); Tue, 16 Mar 2021 06:04:40 -0400 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.30.2