Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp594711iog; Mon, 13 Jun 2022 08:48:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLmVS2cbbOqLf4pyI5reJ9ALSmOubWi1JketBG+5Bk76czoTzzflyxba84DRIfwblA3WNr X-Received: by 2002:a17:906:7791:b0:712:1c42:777a with SMTP id s17-20020a170906779100b007121c42777amr464743ejm.68.1655135323526; Mon, 13 Jun 2022 08:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655135323; cv=none; d=google.com; s=arc-20160816; b=Je50lvLk8gFzAKtlPbzakMZwaGJWosz30Ybr+eJRXrXQL+m3S7zhTUVPIndHwsMa6p vudH9ybV4R4mbiu7WifA0zo35D+AQAbgWm+p1fv+V4KExJwuf94pQfGz4+yIoC9fS91r dVk85iIognu6C6aEo0MI06K32aryUFIO+ip3gjh03KcjtQZkcBGLC9ckZxtBo+K+KULH /2hQmCBcw/xnWpOzimuA/6Y4HvWfds9d5/fFW5beXKWgHkpjP99vhcfseZFA8c1oD9sJ JOMebGhnz3FSvfkOL+68uQQIsEOxRiHjtGEGafRcfmKQ9aMUsRNJIWZWRbRTGcmqqX9t R16g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qp5wO3GeygxlfZYZwWlTjJsE/dvGUkn6GAQEnPqY+7I=; b=XOgYStGiQdIW0SNh1PkSb/woLpuJny3E2VShdfjY+JyiAvdRG7zdOwx9og+c8D2rzm H6jt9n1mt89PJQezpu1qJpMtw5VEZ3c20Z93Pkks/tWuSe0M/C0whE/SftcrqEsnlhH+ J2izi2zgnHQgW4sUQlCz8dQF0g/nymFkOL4+fQwkBGLZvLpx3nKQ7iBJN2eYMuhPXr3+ +Q+2HHCCm2TtUcAd5bGVPRSiefTQzzCxLc60APd6540mX32UCFieAFABfbuim4nAihvq m3UkS5KnFtOMJ6UnBG1vJnJ+ZG2FVySJ8t2s6D+ohXz59eBcmwEyLlCZ2tjbP4AxNWGz todA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rRjlOAgx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a170906519700b007156bee9755si6707990ejk.917.2022.06.13.08.48.19; Mon, 13 Jun 2022 08:48:43 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rRjlOAgx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357256AbiFMNGQ (ORCPT + 99 others); Mon, 13 Jun 2022 09:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355667AbiFMM4E (ORCPT ); Mon, 13 Jun 2022 08:56:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56BD312D0E; Mon, 13 Jun 2022 04:17:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 15FA8B80E93; Mon, 13 Jun 2022 11:17:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72623C34114; Mon, 13 Jun 2022 11:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119025; bh=Jp2oyBPvNl4DGoK37saGae3C6G41R39ozV//4l1WYbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rRjlOAgxPPAAc4DeUhTcKS3yILqlQuxnkjHQle1Sbh7sscNvB/HFwB2jPiqQCOIJn EHwNW67oT/T7LJfNh1qlFmBBm86Iu+Z8468hRJv+2mh7o1Z0TP1GYwgkb7F2vVv5KU pGL4bQEc6Pdzy+vGnR3yZxUHRBPPPtSPhn1IGpHw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongliang Mu , Christoph Hellwig , Damien Le Moal , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.15 106/247] scsi: sd: Fix potential NULL pointer dereference Date: Mon, 13 Jun 2022 12:10:08 +0200 Message-Id: <20220613094926.172750343@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Damien Le Moal [ Upstream commit 05fbde3a77a4f1d62e4c4428f384288c1f1a0be5 ] If sd_probe() sees an early error before sdkp->device is initialized, sd_zbc_release_disk() is called. This causes a NULL pointer dereference when sd_is_zoned() is called inside that function. Avoid this by removing the call to sd_zbc_release_disk() in sd_probe() error path. This change is safe and does not result in zone information memory leakage because the zone information for a zoned disk is allocated only when sd_revalidate_disk() is called, at which point sdkp->disk_dev is fully set, resulting in sd_disk_release() being called when needed to cleanup a disk zone information using sd_zbc_release_disk(). Link: https://lore.kernel.org/r/20220601062544.905141-2-damien.lemoal@opensource.wdc.com Fixes: 89d947561077 ("sd: Implement support for ZBC devices") Reported-by: Dongliang Mu Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig Signed-off-by: Damien Le Moal Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/sd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index a713babaee0f..de6640ad1943 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3480,7 +3480,6 @@ static int sd_probe(struct device *dev) out_put: put_disk(gd); out_free: - sd_zbc_release_disk(sdkp); kfree(sdkp); out: scsi_autopm_put_device(sdp); -- 2.35.1