Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2186517iof; Tue, 7 Jun 2022 22:33:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFqZbDT7sH9RLlEqpg7+M/bDSM2RpUrc9KGFffcbkFh27b5nHkJhVJDodfCLV9+DZl0YTM X-Received: by 2002:a17:90b:1d04:b0:1e8:64e2:38c6 with SMTP id on4-20020a17090b1d0400b001e864e238c6mr20345388pjb.238.1654666418624; Tue, 07 Jun 2022 22:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666418; cv=none; d=google.com; s=arc-20160816; b=yI+vKrObKsqluVZ3wk0uM0FXiEnj/nAlrLUHbsSxYRNeqM7iw0GRfdEIVQXVlFeAHx GJFxj3Iv5KHUaGF/055uF1VbINkiOCDmoj44Cj8v/seN2gVhHn8eAi/6uYjwZDGEBQrL /Vz16KTn5SMsm253M82qQGw7Y23d29T6QPPiU5uD8d2wpJQzLHnNUzqYZTSPnYqoNROw ZwRlvyVo08zuaUJyg0lUWjlDIy2pbQQ+smrRfVf9qekzoQlBV7MfgvUth7ibOPU4/soO UgD2x8Hy6xrYKiOoCsUfj67U9vBiI3tKoVyubWuSd0yMmkbxaQmMqGJ/I8AkwsHSM2tu XGwQ== 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=rP/NUtYtwRIrYlbBMHzC4E0CAdDo1qsSqzDLWJqAkiY=; b=h/DdoIUMwkE24y7BTK0bJSd49/V3dE8zX6Xn8ybC8rqiy4o7iF+cb08Gg1U0ikUgvx 9jknTy7Oo+EptHrYltOPSC7oKHpcquXJIjROHNrtfBpjJ5h22YVLVXx7P2oYLDCd76j3 d9PNhiiUbrftG5pDK0xzrkXZmekFpbShntxSjcOVJiA8I/l0W5fCrBBIXZcSKM74yamX wfK35gPKtMcy8doBtPETyaOHGkIPbF8yY+klYQXGNoXIHGG9pwaD8IE+tjibI0q2O+g4 1+XtIs/7obyOnDG+GW9iTAJrea/dmIIwRggirPq+4LIHx/ppRis3FZ9dxFoTn/dtpR7d 82yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nwwPregZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d2-20020a636802000000b003fd7b18529bsi14852233pgc.364.2022.06.07.22.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nwwPregZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 786D94A096A; Tue, 7 Jun 2022 22:13:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389708AbiFHAf7 (ORCPT + 99 others); Tue, 7 Jun 2022 20:35:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384899AbiFGWUs (ORCPT ); Tue, 7 Jun 2022 18:20:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C08263289; Tue, 7 Jun 2022 12:20:44 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3D41B600E1; Tue, 7 Jun 2022 19:20:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45728C385A2; Tue, 7 Jun 2022 19:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629632; bh=Rf2BtKigmj85vqHrqvMHp6RrUnAF/AVzeXa9HlfYhMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nwwPregZygrhB0sws5UDJ0+FPTVv6btwxsKiOlZw0upx63W7yXTSw3iwM3AiZH0B8 KgFL5l+FpqbRrcAmLQlHk+u+RN9WwMfdtOgwjwg1GVcw9KSXqEd432TvUz+N/+QzPP 17CcVGuVPR2d0eFYEdsBFP0BhXqWw8d5CBuR0ki8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Jens Axboe Subject: [PATCH 5.18 759/879] block: Fix potential deadlock in blk_ia_range_sysfs_show() Date: Tue, 7 Jun 2022 19:04:37 +0200 Message-Id: <20220607165024.895162554@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 commit 41e46b3c2aa24f755b2ae9ec4ce931ba5f0d8532 upstream. When being read, a sysfs attribute is already protected against removal with the kobject node active reference counter. As a result, in blk_ia_range_sysfs_show(), there is no need to take the queue sysfs lock when reading the value of a range attribute. Using the queue sysfs lock in this function creates a potential deadlock situation with the disk removal, something that a lockdep signals with a splat when the device is removed: [ 760.703551] Possible unsafe locking scenario: [ 760.703551] [ 760.703554] CPU0 CPU1 [ 760.703556] ---- ---- [ 760.703558] lock(&q->sysfs_lock); [ 760.703565] lock(kn->active#385); [ 760.703573] lock(&q->sysfs_lock); [ 760.703579] lock(kn->active#385); [ 760.703587] [ 760.703587] *** DEADLOCK *** Solve this by removing the mutex_lock()/mutex_unlock() calls from blk_ia_range_sysfs_show(). Fixes: a2247f19ee1c ("block: Add independent access ranges support") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Link: https://lore.kernel.org/r/20220603021905.1441419-1-damien.lemoal@opensource.wdc.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-ia-ranges.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) --- a/block/blk-ia-ranges.c +++ b/block/blk-ia-ranges.c @@ -54,13 +54,8 @@ static ssize_t blk_ia_range_sysfs_show(s container_of(attr, struct blk_ia_range_sysfs_entry, attr); struct blk_independent_access_range *iar = container_of(kobj, struct blk_independent_access_range, kobj); - ssize_t ret; - mutex_lock(&iar->queue->sysfs_lock); - ret = entry->show(iar, buf); - mutex_unlock(&iar->queue->sysfs_lock); - - return ret; + return entry->show(iar, buf); } static const struct sysfs_ops blk_ia_range_sysfs_ops = {