From patchwork Thu Nov 24 04:02:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 25310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3182170wrr; Wed, 23 Nov 2022 20:22:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WSnHeH6W6Zcf6t73Aen4I4DetbeCIxbqxCVkkgdEOfJWX/QyQW1R4qZJxUUnhhbueS+Xv X-Received: by 2002:a05:6402:2a09:b0:461:30d8:6742 with SMTP id ey9-20020a0564022a0900b0046130d86742mr28057885edb.172.1669263747892; Wed, 23 Nov 2022 20:22:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669263747; cv=none; d=google.com; s=arc-20160816; b=Gu5g2dBsuLfxZonwT2tlBcuaDpOmG/bQpxeBr38I/tJtF+24QVx7j2UYEBNf2jydYC eXra3rGml8oul/alVjowmkBVh+RlUSRxnjyZYlrUdojS+otJqErUklsuCFzermhpBzmi GMK379PuNWwjQiEfxeY3xosrQKac9rI2hqyl0Vz1BMLbPmj8ErBD8jkHG6Q7dKxApKDX jJDWOes+WHXW377/c256zECoMDLIBW8eNX1uvpyO/SBN7/k1DkpIN8WIuc4/sLb/U9/v I+Y2QSVfut+IcsjCO6MHFS+4CKZk+hI3ecHBLYoTBragZVr4N7zY4JLCxfeo/Y9qX+AF 3DrA== 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=60gyWdX0cCn5HcpciA+8IBaWRRbDSlezbWeVg9ZsESo=; b=XT3p8d0r+WJJs61a+5t7Xd5sMhIwiDtjWktGIarUBCte4BQjy5ogg58Nq4tF8rMa8N tM5oOQB9wFEBuEHjcT1GIct0yRIqQOAA5K2TjYyG7MhELXa5ZTI7z/Dpa91toyfGVfgp cP5JC254GYswxVrT0iCrzqmfLSu5nZm5BvmMB92ZUc2HhMtXqPDP6yRj6yPfbaz0PjBj BTeekXtRTEHn5svVHbqUTYamslk0TgZ6TIXSgm8h6N0mZ4doRKWWDm+tBNSHX+YCe+zx lyY/x+tXRM/XQLoePBVn8Ku0nnN6F36ivsqyCp8TWtN9iFiihW3x/Qv7s3rygvNXyXYt lAmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w12-20020a056402070c00b004615ccd71a0si111504edx.162.2022.11.23.20.22.04; Wed, 23 Nov 2022 20:22:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbiKXECk (ORCPT + 99 others); Wed, 23 Nov 2022 23:02:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbiKXECg (ORCPT ); Wed, 23 Nov 2022 23:02:36 -0500 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D001C10F2 for ; Wed, 23 Nov 2022 20:02:30 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-01 (Coremail) with SMTP id qwCowACXnjbT7H5jRa6HAQ--.13010S2; Thu, 24 Nov 2022 12:02:28 +0800 (CST) From: Jiasheng Jiang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] mm/vmalloc: Add check for KMEM_CACHE Date: Thu, 24 Nov 2022 12:02:26 +0800 Message-Id: <20221124040226.17953-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: qwCowACXnjbT7H5jRa6HAQ--.13010S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW8ZrWUCw17Gw17uFWDXFb_yoW8Jw1UpF W3Gw13Wr4rXwnxCrnxJFW8WF1fKa1ktFy8Ka1a9w18Zw1akF4fZFW5J348XryrurZrAF12 vF18K3Wrur42qr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr 1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfU5WlkUUUUU X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750349903858010545?= X-GMAIL-MSGID: =?utf-8?q?1750349903858010545?= As KMEM_CACHE may return NULL pointer, it should be better to check the return value in order to avoid NULL pointer dereference in kmem_cache_zalloc. Fixes: 68ad4a330433 ("mm/vmalloc.c: keep track of free blocks for vmap allocation") Signed-off-by: Jiasheng Jiang --- mm/vmalloc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ccaa461998f3..df3e59f614cc 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2426,15 +2426,17 @@ void __init vmalloc_init(void) } /* Import existing vmlist entries. */ - for (tmp = vmlist; tmp; tmp = tmp->next) { - va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT); - if (WARN_ON_ONCE(!va)) - continue; + if (!WARN_ON_ONCE(!vmap_area_cachep)) { + for (tmp = vmlist; tmp; tmp = tmp->next) { + va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT); + if (WARN_ON_ONCE(!va)) + continue; - va->va_start = (unsigned long)tmp->addr; - va->va_end = va->va_start + tmp->size; - va->vm = tmp; - insert_vmap_area(va, &vmap_area_root, &vmap_area_list); + va->va_start = (unsigned long)tmp->addr; + va->va_end = va->va_start + tmp->size; + va->vm = tmp; + insert_vmap_area(va, &vmap_area_root, &vmap_area_list); + } } /*