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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 DD791C35641 for ; Fri, 21 Feb 2020 08:13:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A92B324650 for ; Fri, 21 Feb 2020 08:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582272832; bh=ufnic7gyL5FpzgTZDCnl1iCho8dXZKGqVcFxBhr0Mj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sf7JUOKvXpPEKRw78yIs2SD8OhJCsFV+moWGXqtfffTsUxp+SXMkg/TfO+w8KwB9x Q1fZDaoRcsoKUZhp7zBz+Wl1H/vkSWcPqfhWxuNkizE48uhTki0rEKDL5CSAy8hPVr 5GYyv7dSZNWQ7nWwooHkMM8nQXm+DXTXPjOHHQCA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733074AbgBUINv (ORCPT ); Fri, 21 Feb 2020 03:13:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:50142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733060AbgBUINt (ORCPT ); Fri, 21 Feb 2020 03:13:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ACD3120578; Fri, 21 Feb 2020 08:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582272829; bh=ufnic7gyL5FpzgTZDCnl1iCho8dXZKGqVcFxBhr0Mj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XT1wegZ1FJ8jruc5QJGDQpS0lIvc77kM1jBwV8k5l7asUN/RDpVyUx5D67BhhU+lI GjGbVyNR7SzYRcMa9aAYyoDBG8oqiVNNdeZ5ZAx2k1jTbPpYDvAS5K/JSz7I9UEO/6 6o/EP6yUC4LJiXjeWrfbc1449DJr76jkMKliFOwo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 289/344] bcache: fix use-after-free in register_bcache() Date: Fri, 21 Feb 2020 08:41:28 +0100 Message-Id: <20200221072416.073453551@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072349.335551332@linuxfoundation.org> References: <20200221072349.335551332@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li [ Upstream commit ae3cd299919af6eb670d5af0bc9d7ba14086bd8e ] The patch "bcache: rework error unwinding in register_bcache" introduces a use-after-free regression in register_bcache(). Here are current code, 2510 out_free_path: 2511 kfree(path); 2512 out_module_put: 2513 module_put(THIS_MODULE); 2514 out: 2515 pr_info("error %s: %s", path, err); 2516 return ret; If some error happens and the above code path is executed, at line 2511 path is released, but referenced at line 2515. Then KASAN reports a use- after-free error message. This patch changes line 2515 in the following way to fix the problem, 2515 pr_info("error %s: %s", path?path:"", err); Signed-off-by: Coly Li Cc: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 86f7e09d31516..485ebc2b2144c 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2472,10 +2472,11 @@ out_free_sb: kfree(sb); out_free_path: kfree(path); + path = NULL; out_module_put: module_put(THIS_MODULE); out: - pr_info("error %s: %s", path, err); + pr_info("error %s: %s", path?path:"", err); return ret; } -- 2.20.1