From patchwork Mon Dec 11 08:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunwu Chan X-Patchwork-Id: 176530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6901661vqy; Mon, 11 Dec 2023 00:27:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZXzwqvlorMxttEyG7gDJzoLrqPs5ZKqfIaohopNvtxvj0qGt7WkOcAqr4iUiqJ5vg6v3h X-Received: by 2002:a05:6870:e248:b0:1fb:75a:778b with SMTP id d8-20020a056870e24800b001fb075a778bmr3756387oac.60.1702283231847; Mon, 11 Dec 2023 00:27:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702283231; cv=none; d=google.com; s=arc-20160816; b=DWIpvjaQi2BX2dH2GTMc/jQ/ewOLSxcEhpnkt6VSyLM4uCQitYzDpo53QqFamONmKI B4Fufs1c4LKKH55GQY3uKKpGiAphU+epwFHWsJyTMlNrEAbl4wTizLnpnawViNWz4YE9 5HJHjrx+4SvQ8jt2I4ZLLyA0z/ibQ+9el1cMQXpdmW5FafWR9vv4l8jRQSIeIX7P4eMl URD839ElT2rqtmHNg9PWP3KF01nfB4tUgHZgTsoLxtYdfsU1Deqp3zQsqf+ZEg5rRJPb qs/6Hnm2H8Im2UVfDu4O+9WJXKCs1T7NK9Ruv7n/OweEpu/vpHnv3QDBFWaK5b8s1xhW x9xA== 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 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id dw7-20020a056a00368700b006ce060dba6esi5784874pfb.240.2023.12.11.00.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 00:27:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 3DF6C80792FA; Mon, 11 Dec 2023 00:26:11 -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 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:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784973342153666327 X-GMAIL-MSGID: 1784973342153666327 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;