Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2194316iof; Tue, 7 Jun 2022 22:49:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzRwgkKYI/IwCnAQKATqOoIjJYzd0Ay+66Yl4NYr2nxIxMwY6qOuEz/PUt6meYHa4x2w7L X-Received: by 2002:a63:a50c:0:b0:3fe:3f58:93be with SMTP id n12-20020a63a50c000000b003fe3f5893bemr247975pgf.265.1654667349814; Tue, 07 Jun 2022 22:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667349; cv=none; d=google.com; s=arc-20160816; b=rSIKc+Pr4GDn6pnlbQJMiLyA4LeplPU1iFQ+bJzD5dMURahiFT9eYGrdv7FqMv7aQs /XEqb2Xl8IoopqPar5itLpYagwy6a8u13X+fjr7z/bHqUVSjrvs51rN7qKXnP0AFcmQs an59BCxDrmU1SdwFErwk9OQlBwV7SWck2B+j8XNzXsSdos0oqKRncaLi+Lfq68Zry3e7 BuW/KJRIdMlLxI7kehZrFanXDVqe6JuseptkPH+AXVEJ0wV3BZTLRzRAk/e2if6UIrls iVFQt3QrFpAw5OeWWzUUvGPzaugqkhz77YHb+MExtxMVCeCefLic/8dOeUMAZ5ZwDZ8W YRNQ== 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=SVHW/2ussCp4Gw31kp4I2ZqpVgQ1Shpvt+zAQhCvgNk=; b=tKeMfH+iCPsPRUpqXtfdbLPuX1zdLGbaCjEi8dyZy9wX6pamsO2X4WckmPXGnYcP8R HpHYyU/mVBi4qzkoTLl2+f0qQJ0OuqV2O8aQ+MOE3N/aXLPG7XxeLr8B9i0sJ+jyDNu+ Rxv+Rk3NW2Z0hIH7DNcbOvSkDgB6UtktqcR9TQsFB4peiULkmrhZJhIgmpF5U7Jq2Vwp MgwOoUpPc4Wt6Z9+llURMdzsSGmkrauUq/zdt+vquwyUIKCzqWkE0kVYfd2BN9igVPz9 mZuGneUBNDbpVW7gfJNqWweTHBnHIvaqFooYeAB7yzMCZvKIt3Fh3D6o7Vx3G7wtP1Nx TRRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i9fCZJ9r; 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 200-20020a6217d1000000b0051bfad76f55si13478356pfx.348.2022.06.07.22.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:49:09 -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=i9fCZJ9r; 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 659B74B77CF; Tue, 7 Jun 2022 22:23:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444379AbiFHBBn (ORCPT + 99 others); Tue, 7 Jun 2022 21:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379238AbiFGWLy (ORCPT ); Tue, 7 Jun 2022 18:11:54 -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 3D5CD259F4F; Tue, 7 Jun 2022 12:19:08 -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 7A0D96194F; Tue, 7 Jun 2022 19:19:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84148C385A2; Tue, 7 Jun 2022 19:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629543; bh=07dGVDfzvZJmA12SM98FMPiVikR3yZALXl/WHor0dGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9fCZJ9ru9BaR+A76Zaw2L6jMkvXbyUARaDAF6NW0ZoExcab42zgvTZqLlA0e4SKp anEWxFU3QhCxAAjF+EmKY5cfRJNcRsHwz8deBw15O877bHgQHSqahIyLjwh8O/B6vF OZgxCHxVD/ZtZ9SA45ZYUmkxv7NP5M/Qsf7GHCVc= 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 730/879] bfq: Update cgroup information before merging bio Date: Tue, 7 Jun 2022 19:04:08 +0200 Message-Id: <20220607165024.045284505@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 ea591cd4eb270393810e7be01feb8fde6a34fbbe upstream. When the process is migrated to a different cgroup (or in case of writeback just starts submitting bios associated with a different cgroup) bfq_merge_bio() can operate with stale cgroup information in bic. Thus the bio can be merged to a request from a different cgroup or it can result in merging of bfqqs for different cgroups or bfqqs of already dead cgroups and causing possible use-after-free issues. Fix the problem by updating cgroup information in bfq_merge_bio(). 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-4-jack@suse.cz Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/bfq-iosched.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2461,10 +2461,17 @@ static bool bfq_bio_merge(struct request spin_lock_irq(&bfqd->lock); - if (bic) + if (bic) { + /* + * Make sure cgroup info is uptodate for current process before + * considering the merge. + */ + bfq_bic_update_cgroup(bic, bio); + bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf)); - else + } else { bfqd->bio_bfqq = NULL; + } bfqd->bio_bic = bic; ret = blk_mq_sched_try_merge(q, bio, nr_segs, &free);