Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2136260iof; Tue, 7 Jun 2022 20:58:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxglKRCy7zCMMptpIifbVhRt4DOF/R11AeAl4zG/VKR/i8J4klkq+haNwms29khVDKLIFbc X-Received: by 2002:a63:2b97:0:b0:3fd:231:eba1 with SMTP id r145-20020a632b97000000b003fd0231eba1mr24847567pgr.144.1654660695877; Tue, 07 Jun 2022 20:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654660695; cv=none; d=google.com; s=arc-20160816; b=EMGcW2X17onpyf3Af7/qwhAhJRbj9twvQZNgL3dNXhyA0C2S8j1m4DlLGlJy1f8ijn aXPuyezaORhWbHfxfcJfWYutdk/oKUE9wB3iweRFgu/17TI0l6PJjh1sck51mrgLqxmr XGK8mCSub82gEvE5Lsy78rf/rTjTk8/Nwq/GOtiq5sswuEtdSH+kzuUxW6T8xtJIuKDX rjGjHQc+SGgp0TU2lXpckCuUtMBuxKoME8a4/oDt/25XCGDjz0Wf1TbZiPgHBnPtaEZ+ G/o1+FY75+WcsNbeYPzQv2t5qlxhz6Mp9pJsV2jyg/ajXGavuJwqpqIGg7qCQa7r7HT9 Rlzw== 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=V3nqC+9aapcnB+95UODIohuQqcxYpm9O79ij7agPWgaRKzP0RvXEWCyMvC9rVrDPXI e7niVzvAgjrScvtyI3igVyQi+1YW28PBJnsCptBLLU3sjnlHiH/gJ0y2JiPJfoFVNxwS s/t8Atjd0p2DMg7R/a+fxrJOK7NTufqA2yLv3Wm8BLdlab3cBWWAffd33+y3d7GhyIxH +3d0LMxov9hg23od4zuuiBjsfHcDZjkGU8DGI8SS22Hpr4S2L3NjcdGjUw/aQ5l1YcL6 9TZR0/0P9/bj1kEtWEWrDZb69JTWKFq40ICNsvBnVu10Yxr2a6evTGPJGMZsAAsrC9Im 0RIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a++uQWqQ; 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 f69-20020a636a48000000b003fdb97e14adsi10289659pgc.752.2022.06.07.20.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:58:15 -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=a++uQWqQ; 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 048452533D7; Tue, 7 Jun 2022 20:21:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380511AbiFGVjE (ORCPT + 99 others); Tue, 7 Jun 2022 17:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376933AbiFGUsb (ORCPT ); Tue, 7 Jun 2022 16:48:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D90E1F62FC; Tue, 7 Jun 2022 11:39:47 -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 D94DFB81FE1; Tue, 7 Jun 2022 18:39:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43A65C385A2; Tue, 7 Jun 2022 18:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627151; bh=QkiFAHOJFLYpTE4pDqY8HSQkwJMKiiJioaFUGFDAQSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a++uQWqQTw9BIazdjHYlqv56UguIkM4FS5kXrULLb6+orv+c398zHhqF1jjiRrmXg lxgl18AwAzwewQQB/s6vJ2Mj7TDmfW/j2I1yLWQ4lQMAhvdjC1uzc2snAMfg9UX7Zs QR9SuAjlvtJlVDzFDbYyCkso+KcjKA8r9pSW/8WE= 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.17 635/772] bfq: Make sure bfqg for which we are queueing requests is online Date: Tue, 7 Jun 2022 19:03:47 +0200 Message-Id: <20220607165007.647021878@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@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; } /**