Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2205717iof; Tue, 7 Jun 2022 23:10:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMSREPM3y6h/bPI01uPluU9GXoYjKUKjowgbs+YKe7GaXTjYuC2gAEykgAuPrrlC8Nr2XF X-Received: by 2002:a05:6a00:24c1:b0:518:c52f:f5 with SMTP id d1-20020a056a0024c100b00518c52f00f5mr33340550pfv.15.1654668621577; Tue, 07 Jun 2022 23:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668621; cv=none; d=google.com; s=arc-20160816; b=h9pk4q7axZj/Dq94T7pTlRW4zlENW7ktWBXZ1hEeGl1AZFTv9YEJS+Zl4vmRFxks7a u0VRaho+ZLM35eOqlE117XISEvqJIWzp3R5ZTTMgn63E8/XmerI5RXNGcRz16ggN7Zrm VCOo4ZRVgyJM2KVcWnej4hshc7qP5X71YOSRiG+CQcYHvaSOmhUWPl2T4oWRvUdT8d0O bZMfEYccpaJjCoy8PAxSyF7+oBZClvFT/uWoykLD1uYW6X0w9PS1vGJa5B+HkB5pFhoQ ApPJ3hjIQmNUtEi0iGuuMx3B0wapq5UPM5PcyCCmneUq3BOCLI/BdtlkNB58L/zI8Ulu K4mQ== 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=j7qYnE3AFZCy4D+S/bL/RP0qHtp+d/fhAigA9xzs0zU=; b=morN2Vfze7PSj7FYWns/TkXyo1YbOQK2tNXWoC+SXkMbLEomFCysBpJF1kYKMUgLGL Q4AIyqS6BAp7TCo7kx9qVygXyRzpI5BUTG8RYqHj7ZLzPVXwwo0WuDRwl9Kov9/LfxQj /QeobV2FaSifU+/kq6baZV5zknZgpEdQqXmfqPLBFk14DtpQntv2SSHEsk6HQLTCHg81 VwDktWjQVSyb43/uqBXtoFSKaZHtKywlFtBPz0n7s+7TeCh2C2g0yMdEpE8DzN8Sx3EK 4/EvaSmLeaA8CckrO/Fbf5aItYdqO53XphG2NybwH5uTRCM5d/gZVCOGL47QokEtUmgf Ae9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qRXLs1MS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id t1-20020a17090b018100b001e30236ae86si25211696pjs.112.2022.06.07.23.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:10:21 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qRXLs1MS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5F8728E71B; Tue, 7 Jun 2022 22:32:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380806AbiFHBk3 (ORCPT + 99 others); Tue, 7 Jun 2022 21:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384259AbiFGWM5 (ORCPT ); Tue, 7 Jun 2022 18:12:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 163AE25C1D6; Tue, 7 Jun 2022 12:19:29 -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 1548C61929; Tue, 7 Jun 2022 19:19:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26246C385A2; Tue, 7 Jun 2022 19:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629557; bh=QkiFAHOJFLYpTE4pDqY8HSQkwJMKiiJioaFUGFDAQSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRXLs1MS1My/Q9JWnSpyKxA0BAo7f1NyT/DNvTuLy088yfpNZnTdBZ341uzPALHG5 +VeDsHie6uf6ypLmU7ug87WB+vqzi27DmXEeM4r27DF98f0G6TICelnHTA+Jr9+l5E 8Nms6RnvdUcmUqKrD0YKE8H4xwrDASKcit0qnS7E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "yukuai (C)" , Jan Kara , Christoph Hellwig , Jens Axboe Subject: [PATCH 5.18 735/879] bfq: Make sure bfqg for which we are queueing requests is online Date: Tue, 7 Jun 2022 19:04:13 +0200 Message-Id: <20220607165024.192434952@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: 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 @@ -612,10 +612,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; } /**