Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1304805ybt; Sun, 14 Jun 2020 18:12:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqFj8YS7CGE5RiVqp165AW65Di+eOLPin3NSRMOYdJRy+nSkutrRW2hoO5/fPVNDf9mhr2 X-Received: by 2002:a17:906:4756:: with SMTP id j22mr24414698ejs.490.1592183554584; Sun, 14 Jun 2020 18:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592183554; cv=none; d=google.com; s=arc-20160816; b=B0GNAd+H/xol+dVq+aQ3SMsy0Ba7JuZgD1DWJyVFzqAtDZpsAjVyTNIE6x+pIpoG5y J6w3clUBdJqQaljL/mA44aV+0//FBIbqRtbO8Fp3AWhwSg/vtvwKYe7HhSVtLYAroLmb mAZsuokXMQ1zuFLeDwi1mKYD+UEm4JS75yBqWysfUdt4BDolN4cCHOQezlNBQ2cYAkb+ 1tZm1rWwo8erG/EMTezIPmIAat53/d/5MeLWorQfy2rHFCuxoI2t1Ss1Kj1nXtwrQS0o aePlMZFXTti8xR2i1967AVV/jWOD0X5MJtSHFXtutssFmphxbPbzyc2Yw9Jpc0N9yD9P 9/hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=rgK7t6u5LehBGUDX5/cbQDfaIK+LuFZm3GbaipZEPDg=; b=Vm5Miz0WFHPyXydjtSzT3sqhs/EgXATgR21jixa9rLrMkGWR42nLZjKgOYF8PioVne yBvI7dvraB/pyjmTYDnpdFrAMaDWlr2nWjSs9AhQnlPsISFq1fR3Y8yJXUX38ZgmJvyo KhSdzM9YSQMeLiaYXSVW5ns9VziF45ZJ6tnzpVFpIDKt1wR3HNB6LRr9todKsUcCzunu zCsLuXd42TP1MpcGcuqAxFEdPBSE4CSqX5H4WabI1ABO+uspRRFio+eh/shS55WqcFat gd3XkFpPBqqUtq8JkSB28bQIdAZjjy3VZipXkBDDWNL+eReIBS1n+5uU6aMtDgz9n0ur pkEw== 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 ha26si8495617ejb.533.2020.06.14.18.11.59; Sun, 14 Jun 2020 18:12:34 -0700 (PDT) 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 S1728063AbgFOBID (ORCPT + 99 others); Sun, 14 Jun 2020 21:08:03 -0400 Received: from lucky1.263xmail.com ([211.157.147.133]:59834 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728039AbgFOBID (ORCPT ); Sun, 14 Jun 2020 21:08:03 -0400 X-Greylist: delayed 387 seconds by postgrey-1.27 at vger.kernel.org; Sun, 14 Jun 2020 21:08:02 EDT Received: from localhost (unknown [192.168.167.70]) by lucky1.263xmail.com (Postfix) with ESMTP id AFC8AC4066; Mon, 15 Jun 2020 09:01:26 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P7894T140607611721472S1592182885179202_; Mon, 15 Jun 2020 09:01:26 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <6e5d4ca0e9834636d81f3592b3db92c0> X-RL-SENDER: jay.xu@rock-chips.com X-SENDER: xjq@rock-chips.com X-LOGIN-NAME: jay.xu@rock-chips.com X-FST-TO: akpm@linux-foundation.org X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Jianqun Xu To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jianqun Xu Subject: [PATCH] mm/cma: fix NULL pointer dereference when cma could not be activated Date: Mon, 15 Jun 2020 09:01:23 +0800 Message-Id: <20200615010123.15596-1-jay.xu@rock-chips.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some case the cma area could not be activated, but the cma_alloc be used under this case, then the kernel will crash caused by NULL pointer dereference. Add bitmap valid check in cma_alloc to avoid this issue. Signed-off-by: Jianqun Xu --- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/cma.c b/mm/cma.c index 0463ad2ce06b..488496fa2972 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -425,7 +425,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, struct page *page = NULL; int ret = -ENOMEM; - if (!cma || !cma->count) + if (!cma || !cma->count || !cma->bitmap) return NULL; pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma, -- 2.17.1