Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443179iog; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDDH+/xwtPkxitG9OG7G7VmlWMAG7M3TwJjG81x2/IFscszneqX1Yte5BEC4qIx6fvX9KP X-Received: by 2002:a17:906:73dd:b0:715:777c:b7a8 with SMTP id n29-20020a17090673dd00b00715777cb7a8mr8915932ejl.607.1655125590607; Mon, 13 Jun 2022 06:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125590; cv=none; d=google.com; s=arc-20160816; b=fiTTN4WssiFj2lNPY9Sa/1jT7quFbs1I6hSqKqmscfOx+xd0M6vtBSuzUKD50PA/wJ su8TbDeB0I0L39OTWTxBmC/Yg5BZWUrk1lljrqRw2DT5c/2b/z3dFl6XYkLZlZLCMM8G 75c95WqqMTcyjhHsJLupmYaYNJUG9iJgOO1iO1skuF7XAaM4k1afGJyPhgehEqrzZP1L Q0bTeZKmv0e+1EZUyR9l/odEslDC/FHV8DGTQiTO/ZnUfnrWdvE2KRu5YnhxnVsePa9v OucsJA98uBy6ySgZoqxjark2CGTJkVG62Xr8yiHWCkVppaLzjoG+FmC5vyPv0JW9/oE6 zrFQ== 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=hYb95PxNxsYvJI80MFj5WQF7Aoa0mccRWFqM5Nb7dBg=; b=1JfCRfpfEQogCIO0SKzLRdz5eB4TlZGk0EK4jXXMX+tsE0/pg9HH6ABJEcMYV0WiUk A6aZ6ViDyUQ0tGACAaekRThUFP2sARDTjOdk/PmQ0f/ADrvCIJHeCDITAc+5TppSHbX+ rCaB50XDv3cEGj4DrX9qDL9ESazCaOM0gYKlW5IDdFQLdnt+jh8JD9G98jb980xoZ+uv Yux5yKj4zi87bSU0nUSAXVtoqAlquxJEji0+LxYJAfJMW7bXptAJIJGrT7IQgVbkIqZr 4yLJI4z9XRZPsWCCIkd53jXSBLCjj0f6FaSKlTkN+Y7dBuWA71r7JFptriAvbLVzm+m0 kung== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XfVIfWdX; 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 z21-20020a05640240d500b0042b6bc4ce6fsi8622091edb.540.2022.06.13.06.05.51; Mon, 13 Jun 2022 06:06:30 -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=XfVIfWdX; 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 S1354233AbiFMLe7 (ORCPT + 99 others); Mon, 13 Jun 2022 07:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354434AbiFML33 (ORCPT ); Mon, 13 Jun 2022 07:29:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D110DEAE; Mon, 13 Jun 2022 03:44:37 -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 49882B80D3F; Mon, 13 Jun 2022 10:44:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF4CCC34114; Mon, 13 Jun 2022 10:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117075; bh=RWxaM1YLpMpbFkfbSS+YgAmGIuSLrMLBgNnh7aWAorc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XfVIfWdXJTssvMtT7UTaIjLq3km3cDP8ZeUV2Yodxw7okmoWUEKx8HG+tQs5jL5lr f2APJ4u7fMKIPb51IwWyIhWDiqFHVvacQiSaac+xD1MsqeqaoeHgw8SDORbuweY8Eh ZbCnLJfuGIF2jVze3N54MdOUpRcWt7NLswB0VBIY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "yukuai (C)" , Jan Kara , Christoph Hellwig , Jens Axboe Subject: [PATCH 5.4 278/411] bfq: Make sure bfqg for which we are queueing requests is online Date: Mon, 13 Jun 2022 12:09:11 +0200 Message-Id: <20220613094937.095170833@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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: Jan Kara commit 075a53b78b815301f8d3dd1ee2cd99554e34f0dd upstream. Bios queued into BFQ IO scheduler can be associated with a cgroup that was already offlined. This may then cause insertion of this bfq_group into a service tree. But this bfq_group will get freed as soon as last bio associated with it is completed leading to use after free issues for service tree users. Fix the problem by making sure we always operate on online bfq_group. If the bfq_group associated with the bio is not online, we pick the first online parent. CC: stable@vger.kernel.org Fixes: e21b7a0b9887 ("block, bfq: add full hierarchical scheduling and cgroups support") Tested-by: "yukuai (C)" Signed-off-by: Jan Kara Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20220401102752.8599-9-jack@suse.cz Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/bfq-cgroup.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -591,10 +591,19 @@ static void bfq_link_bfqg(struct bfq_dat struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio) { struct blkcg_gq *blkg = bio->bi_blkg; + struct bfq_group *bfqg; - if (!blkg) - return bfqd->root_group; - return blkg_to_bfqg(blkg); + while (blkg) { + bfqg = blkg_to_bfqg(blkg); + if (bfqg->online) { + bio_associate_blkg_from_css(bio, &blkg->blkcg->css); + return bfqg; + } + blkg = blkg->parent; + } + bio_associate_blkg_from_css(bio, + &bfqg_to_blkg(bfqd->root_group)->blkcg->css); + return bfqd->root_group; } /**