Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1594902ybv; Thu, 20 Feb 2020 23:58:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxOscckzgoQGSnzCjea5TmN1z6Vm4SvflZ767eLG1GjYYnBpb3JcO8LfNZihYMH0DrR6tMz X-Received: by 2002:a05:6830:124b:: with SMTP id s11mr26461879otp.333.1582271899233; Thu, 20 Feb 2020 23:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271899; cv=none; d=google.com; s=arc-20160816; b=cN+zekaQWRE6fQe6ltJTP7Vc0M8RtZdGrdCvj+R7lCeuznVau6wnC/CExNh7kFHIyY Gj5EbR/XQUDAhqcF1L1e2NyuTDlW8OCjDSvfIEnO5yCtiGqIlyivqxjOofXNWB9Nznve RybiYPCf0Uv/gWWRTVedXKw/ckeRFtBzGsn5QNKsiLixGNtJEQXecr6UBGDK6CXuSj1u 8y5cd/WWNkg/sZM7+9OesgfuBO3wpOSL8rjq5Unv5IjW/n8X8otiFq8BEnuH3R3HZKIs c97R8yN0VvNmbBxTvcAK5bQnt3EwRmuhpV7IpPYzLWrjoDqia2qPoIE3s/tfqY1QoQr0 +R3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BkH5U/3sL5IO+EwEhrb7V+h60ThpYqhH/b4sUih6Q4w=; b=qLPw9L3ZEqQWm6THWRxQY2InYDqRXx0SN05GNZh8N7t4bE3Bd/kJHLH9XAq/rD/rzV Wu51W/6G1DZbCMfvD/IGxV1Ki4ySwvtOKuumHyvVgvGaYAMUkwMzvORCku7F6nR3H3aA /c/aTa3o4cf4ZvJL4wsc6mcvsrPFenmHD0Jq0xFJFppD+/OnulvsqawwJCliLJGlRvep z6ggtHq+6sd43RfvO6+KenZKJUxMJK4HEEWTGdM2qww2XsK0D7EhjADAT1orKHsvIAaQ iVot/vF2W6LsZBceMRujR5u/KtSOIR5ekqtMdtr+YYiUABbgQriiddRNX5RREGjzOaNO Mf3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yhRMmF4A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u123si443873oif.84.2020.02.20.23.58.07; Thu, 20 Feb 2020 23:58:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yhRMmF4A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730730AbgBUH6F (ORCPT + 99 others); Fri, 21 Feb 2020 02:58:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:57776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730036AbgBUH6D (ORCPT ); Fri, 21 Feb 2020 02:58:03 -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 B63A820578; Fri, 21 Feb 2020 07:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271883; bh=7GTzFRjxuS1PYuCP5jZ9FakEZ80lREG4UThrnZSeHJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yhRMmF4AkVtSmOuMKmvdxQyyq1gSrSwcXYcOr3ys+jXZAcEZcDfeG+whXKenGD1GW 0JqiTidyEepDm2gFpXtnML+4fN3lRsqwfCSPK8Ts0/5aeAQjf/pkzbC51eiuqWSFjX 3MTHxXIBNdAwvxOugfu6857TtX5l8Xg1z5tpVHB0= 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.5 334/399] bcache: fix use-after-free in register_bcache() Date: Fri, 21 Feb 2020 08:40:59 +0100 Message-Id: <20200221072433.516792813@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@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 bd2ae1d78fe15..05cb94664efee 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2475,10 +2475,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