Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2890415pxb; Tue, 24 Aug 2021 09:58:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3Dp3eo8Bp2ubAeV5vOBWdW1aDfzXvDF90PlIolZntTV2k0MNS4foySwTrT+DlkHxLUFX0 X-Received: by 2002:a92:1908:: with SMTP id 8mr27324690ilz.149.1629824305910; Tue, 24 Aug 2021 09:58:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824305; cv=none; d=google.com; s=arc-20160816; b=d1RFq6ZXtd+No1uNiWnPMKkK+qCGdTMk7nFslyIu4gWJ0eZ2cW7J2O39A6GNd8L57I kyzB55Hip2URX7iGdFFA/RW4yGlb6QP7MLpJq8qP7mNcWAA0T+1RTo2EqwkVQWPfuvON iFmv+x088WkyS3pqo6jAB66gcWDWQYLPYYxesFLHVbVkdW3H2Xq3qIrxKMgcpFhVFU4O Ygf/acktgLDNZy8cMNxgbN6+Xai4pNh1A0nBjxDWtHlnyL8PjxWi4PUce6wl5E4f1DX0 wH1FEgXYqyPtuAEADClLGmcza4nhx+yoksgVlgnF60wr7Iz75HWCSBKlw30DTpwFaw+a SGeQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SUBOUQC/XcTVdyfaGjXocsomGhVxz/U1y54Kcp6TN64=; b=yFg6qa3gz+DzMvV3bSf0hFbn2khdggA5tOJ+5mzG5aWNDJNRzT/uHJ/ITMWy8NJZE/ dAGwqXcLJAepUUuu0Hx3mD4Pxlhosx/Vr71tIJpW9njx7gTqJoZ1LrPLjtVODmg0QrLL 8+6kAY022jG6LWMlGEbsl01FjWd3S6ZIFkRTlpiRf7XG9hlzZCEc3o2ypqbsdVniweKa U/IvOWFjpETJdOrrUpKvSRq3RxMEWNBGDp3NHkstiI+3YtERAE9/m74AbnC68FL19E4H bzJurEMxjhaWcdMfofR81Kq1ZWrJYJX6DK4Ftcdpl8YRHYmcLZxrhZBSPQmU/dCsAv4E kb4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ni/s5vBD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si13376157ilu.26.2021.08.24.09.58.13; Tue, 24 Aug 2021 09:58:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ni/s5vBD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234284AbhHXQ5e (ORCPT + 99 others); Tue, 24 Aug 2021 12:57:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:38972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233820AbhHXQ5G (ORCPT ); Tue, 24 Aug 2021 12:57:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7239361368; Tue, 24 Aug 2021 16:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824182; bh=6oEFXFdvRBDkc3zbc0r2lGvzgXpWJpySRRUiKT+8NGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ni/s5vBDkZyuHphWuDDaljmxgDZrfeNCJcvjZTArCN0B1EgeF/4ZI0a6ZpyYchXlV i1Pgpk4as0VdAXvu1PTmdszJNubLH1J9bHFuQHy0WFvKuARVcJ2Uxu7aanfIyguhxV KTsjPCHvKbHDTj1SVgkoze7pBQ39OwB42HrhsbU04bQVl8TPgQmIopcy+bmiI5tkxD mlcfPtYL9lWX9c6pfbOszugn0twW5XUJ6WS/bpymzBaARfG44X04z0m166IyRxiP/9 O6INVRFwoK5ifL74gea8VuUexn1WA9iQiNkl2p+tFaY+RcG+R/+/5lKL3Qfrytceon MJu19/lowT+Ww== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ye Bin , Bart Van Assche , "Martin K . Petersen" , Sasha Levin Subject: [PATCH 5.13 013/127] scsi: scsi_dh_rdac: Avoid crash during rdac_bus_attach() Date: Tue, 24 Aug 2021 12:54:13 -0400 Message-Id: <20210824165607.709387-14-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ye Bin [ Upstream commit bc546c0c9abb3bb2fb46866b3d1e6ade9695a5f6 ] The following BUG_ON() was observed during RDAC scan: [595952.944297] kernel BUG at drivers/scsi/device_handler/scsi_dh_rdac.c:427! [595952.951143] Internal error: Oops - BUG: 0 [#1] SMP ...... [595953.251065] Call trace: [595953.259054] check_ownership+0xb0/0x118 [595953.269794] rdac_bus_attach+0x1f0/0x4b0 [595953.273787] scsi_dh_handler_attach+0x3c/0xe8 [595953.278211] scsi_dh_add_device+0xc4/0xe8 [595953.282291] scsi_sysfs_add_sdev+0x8c/0x2a8 [595953.286544] scsi_probe_and_add_lun+0x9fc/0xd00 [595953.291142] __scsi_scan_target+0x598/0x630 [595953.295395] scsi_scan_target+0x120/0x130 [595953.299481] fc_user_scan+0x1a0/0x1c0 [scsi_transport_fc] [595953.304944] store_scan+0xb0/0x108 [595953.308420] dev_attr_store+0x44/0x60 [595953.312160] sysfs_kf_write+0x58/0x80 [595953.315893] kernfs_fop_write+0xe8/0x1f0 [595953.319888] __vfs_write+0x60/0x190 [595953.323448] vfs_write+0xac/0x1c0 [595953.326836] ksys_write+0x74/0xf0 [595953.330221] __arm64_sys_write+0x24/0x30 Code is in check_ownership: list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) { /* h->sdev should always be valid */ BUG_ON(!tmp->sdev); tmp->sdev->access_state = access_state; } rdac_bus_attach initialize_controller list_add_rcu(&h->node, &h->ctlr->dh_list); h->sdev = sdev; rdac_bus_detach list_del_rcu(&h->node); h->sdev = NULL; Fix the race between rdac_bus_attach() and rdac_bus_detach() where h->sdev is NULL when processing the RDAC attach. Link: https://lore.kernel.org/r/20210113063103.2698953-1-yebin10@huawei.com Reviewed-by: Bart Van Assche Signed-off-by: Ye Bin Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c index 25f6e1ac9e7b..66652ab409cc 100644 --- a/drivers/scsi/device_handler/scsi_dh_rdac.c +++ b/drivers/scsi/device_handler/scsi_dh_rdac.c @@ -453,8 +453,8 @@ static int initialize_controller(struct scsi_device *sdev, if (!h->ctlr) err = SCSI_DH_RES_TEMP_UNAVAIL; else { - list_add_rcu(&h->node, &h->ctlr->dh_list); h->sdev = sdev; + list_add_rcu(&h->node, &h->ctlr->dh_list); } spin_unlock(&list_lock); err = SCSI_DH_OK; @@ -778,11 +778,11 @@ static void rdac_bus_detach( struct scsi_device *sdev ) spin_lock(&list_lock); if (h->ctlr) { list_del_rcu(&h->node); - h->sdev = NULL; kref_put(&h->ctlr->kref, release_controller); } spin_unlock(&list_lock); sdev->handler_data = NULL; + synchronize_rcu(); kfree(h); } -- 2.30.2