Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3824622rdb; Mon, 11 Dec 2023 00:27:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUjs1EOCoPHMkYwFG0zboxnnQQyu/CC+ymrbQ9a3y9rEhUazFu1dnLTY7juUupuejbyx18 X-Received: by 2002:a05:6e02:1b07:b0:35d:5995:798a with SMTP id i7-20020a056e021b0700b0035d5995798amr7205303ilv.36.1702283232380; Mon, 11 Dec 2023 00:27:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702283232; cv=none; d=google.com; s=arc-20160816; b=s6PFXTLtIEfgNP13kCo4nN0yqHIVSQU4b7L+5dx09qNQlmdVRPuOoojYRVwfmw6S1M iIvV57AVjmQkPXVkW68O5QCRlyw639RnByYWqi7ZF05c7sYsSiIC8gJ0o4FSIFm40Uev X1qlAXRPTuVj7I0Cu7T5YgvxdEXPV02kl/TNomyAKpEJAXHTG1iXE67QPbqRWchzZz+q Tk+ZLMO/pIoe2t0U+xT6iNKajVCAEnsk/0l39DhEF2nwrckeAa/cDQzIhOz2KsbuCWOu bJc9ZarrCJSoSK8iZGuV5cwCmd2Vqhke3qgdx/lXb4UDc2I8eyQGenk3vm/f/wXOlm4L /tDw== 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=I/V+1xnYiclVJvGDOLcP2jT6llM3qjwdiN3ErShUqps=; fh=KmKZSL7P1yLeSIwHXLrFy45cmaWlUc6YqEoIG4WBimE=; b=LMSNTsjHsYsXalV8LIaRSjaYqc6r1m1VJbHRitE8KV1xncv/YcHaV/eeRY1YhkT6lD hDSRGAUS1HzNYN2395vYS5NOt0j4UJ4fGq8mnD/drQEXb9lcRnLJ8o3BjOxR4itbts1e ddNXQPyIk2Ri8H1XwfITSzTCb8jqEfFe70bJqLTuP88rd3Uy6ZjhmnKXnpK38u2ufxIG qlKmn8dkaamihj35sOnqLjZeJtMXe8ECVgtNgjUtv+Fe4AmZEen8QNZLc5tCfIOz3T5Z DL+2Fs59ffasuHzpKHnXdi8NxOigK4MRMh8KKDsgjusY0gdcFH8NJ8i5ADCHTLMWwnm3 I4Qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 11-20020a63154b000000b005c1b58a321asi5684038pgv.411.2023.12.11.00.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 00:27:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A166980779AD; Mon, 11 Dec 2023 00:26:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234084AbjLKIZf (ORCPT + 99 others); Mon, 11 Dec 2023 03:25:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234001AbjLKIZX (ORCPT ); Mon, 11 Dec 2023 03:25:23 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319CDED; Mon, 11 Dec 2023 00:25:27 -0800 (PST) X-UUID: 3e989875f99e4d8eb39bd82da1667e6e-20231211 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:58c0d297-7572-4453-a73f-1fd9a016948b,IP:5,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-10 X-CID-INFO: VERSION:1.1.33,REQID:58c0d297-7572-4453-a73f-1fd9a016948b,IP:5,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:-10 X-CID-META: VersionHash:364b77b,CLOUDID:5286a573-1bd3-4f48-b671-ada88705968c,B ulkID:231211162515Q51SE72Y,BulkQuantity:0,Recheck:0,SF:24|17|19|44|66|38|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 3e989875f99e4d8eb39bd82da1667e6e-20231211 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 342527585; Mon, 11 Dec 2023 16:25:14 +0800 From: Kunwu Chan To: colyli@suse.de, kent.overstreet@gmail.com Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan , Kunwu Chan Subject: [PATCH] bcache: Fix NULL pointer dereference in bch_cached_dev_run Date: Mon, 11 Dec 2023 16:25:10 +0800 Message-Id: <20231211082510.262292-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 00:26:22 -0800 (PST) kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Cc: Kunwu Chan Signed-off-by: Kunwu Chan --- drivers/md/bcache/super.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 1402096b8076..40b657887d3b 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1053,6 +1053,12 @@ int bch_cached_dev_run(struct cached_dev *dc) NULL, }; + if (!env[1] || !env[2]) { + pr_err("Couldn't create bcache dev <-> fail to allocate memory\n"); + ret = -ENOMEM; + goto out; + } + if (dc->io_disable) { pr_err("I/O disabled on cached dev %pg\n", dc->bdev); ret = -EIO; -- 2.39.2