Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4734640ioa; Wed, 27 Apr 2022 09:57:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB6f+DzrmlEFUJ5oLHLJLLzY+KlAfLvRz5DfJuaYF9BzxUy5mDXAsmaGCG+QRcco31d6C2 X-Received: by 2002:a17:902:9309:b0:156:983d:2193 with SMTP id bc9-20020a170902930900b00156983d2193mr29357329plb.158.1651078629256; Wed, 27 Apr 2022 09:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651078629; cv=none; d=google.com; s=arc-20160816; b=DILJVDjYt3YAIXfL9aOhdJgfDVPfeDQX9ePDBdIf3waNl67CBY+KgkOYO2SIw0vt13 xWkjqV4/Z2FaueaaEA19Wkx0gZI2mSSl4mYCfNOPkgvVzSQWQ49SB4zzJAmbzE3K8kCd 8ZSHU4YcSMGqzUmJJazc2V33w3SX7ynBCfxA0Uw3PTJ+Y6wa0oJvIWz4o/MF5DIVQBsG 5fxRRZ3Z/B6+kn6lEb+jC0fp+662rydPqJNqn1+N9EZ9J8dsk0Ig2pdLgB62j6Q99LCF 7qXsBsGR3duminVbbKBpCknfJ2jo521D+Gl12h7QbuvmlyIfsdl+dBpfqQvcdVmecDig cFoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:cc:to:from:date:subject:dkim-signature; bh=Cbg75PUlXZajnRxt3xMCnhVcFuPLrtdlN4tn+AcY6xI=; b=wWjWgTAAz3BX8ghxhhRDziUvXaM1NWrEufZ0b+fjgGlhCHCfzZdswkBwjAaxk+9Ooy 5AcZ3IY8r69qG4ciYU4JRxqiRFkLidPi2FNsp7eB0wPgc+Fc/RBnzMuIhmff06+Mlqi4 moE4Zli6iBknwZpW0eU3GjOR1GXIdAaXMnN2BZOe93i0FnqYE6Mp6NKVztRFtZcC3lNT E3DjTUJ9ec9gCUMks8bjET9pn6tW0KN0LpqSDWJQLGsWLfZnfLn/TBuY+ksB6S1DILv1 opfJvhlPK0ti8jSac63GEp7UOl2vYmTujR7Whc4xMi6tHFmz+K7SjDqgkLOt/BKdG24u eNqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=c1HLNC1w; spf=softfail (google.com: domain of transitioning linux-ext4-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s3-20020a170902988300b001582fa35afasi2039908plp.190.2022.04.27.09.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:57:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-ext4-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=@amazon.com header.s=amazon201209 header.b=c1HLNC1w; spf=softfail (google.com: domain of transitioning linux-ext4-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB624DF7D; Wed, 27 Apr 2022 09:27:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242887AbiD0Q1u (ORCPT + 99 others); Wed, 27 Apr 2022 12:27:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242936AbiD0Q1B (ORCPT ); Wed, 27 Apr 2022 12:27:01 -0400 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E9D266DB7 for ; Wed, 27 Apr 2022 09:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1651076512; x=1682612512; h=date:from:to:cc:message-id:references:mime-version: in-reply-to:subject; bh=Cbg75PUlXZajnRxt3xMCnhVcFuPLrtdlN4tn+AcY6xI=; b=c1HLNC1wvUEKlQgmJVyjh9Miw02XPBzl1FqX8bxGqWbr9Nq6syTmXXlN PCU9qfS4qgTj1PyKRF0jp/Yq2Yu7S3lQd7sB9p/ZGXUAm+jCuJ/0FILzl 9V/9PGQxZlPCJqJ+RkffWDcvYblhDIk/Ao4Enm6OJC95Wk2u7fLYsque+ Y=; X-IronPort-AV: E=Sophos;i="5.90,293,1643673600"; d="scan'208";a="196791255" Subject: Re: [PATCH] jbd2: Fix use-after-free of transaction_t race Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-2d7489a4.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP; 27 Apr 2022 16:21:48 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-2d7489a4.us-east-1.amazon.com (Postfix) with ESMTPS id 57982951B2; Wed, 27 Apr 2022 16:21:47 +0000 (UTC) Received: from EX13D01UWA002.ant.amazon.com (10.43.160.74) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Apr 2022 16:21:47 +0000 Received: from localhost (10.43.161.193) by EX13d01UWA002.ant.amazon.com (10.43.160.74) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Apr 2022 16:21:46 +0000 Date: Wed, 27 Apr 2022 09:21:46 -0700 From: Samuel Mendoza-Jonas To: Jan Kara CC: Ritesh Harjani , , Message-ID: <20220427162146.3nj3czri4krdpy3c@u46989501580c5c.ant.amazon.com> References: <948c2fed518ae739db6a8f7f83f1d58b504f87d0.1644497105.git.ritesh.list@gmail.com> <20220426183124.phrwsl77bch5uljx@u46989501580c5c.ant.amazon.com> <20220427111726.3wdyxbqoxs7skdzf@quack3.lan> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20220427111726.3wdyxbqoxs7skdzf@quack3.lan> X-Originating-IP: [10.43.161.193] X-ClientProxiedBy: EX13D10UWA003.ant.amazon.com (10.43.160.248) To EX13d01UWA002.ant.amazon.com (10.43.160.74) X-Spam-Status: No, score=-2.5 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 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-ext4@vger.kernel.org On Wed, Apr 27, 2022 at 01:17:26PM +0200, Jan Kara wrote: > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe. > > > > On Tue 26-04-22 11:31:24, Samuel Mendoza-Jonas wrote: > > On Thu, Feb 10, 2022 at 09:07:11PM +0530, Ritesh Harjani wrote: > > > jbd2_journal_wait_updates() is called with j_state_lock held. But if > > > there is a commit in progress, then this transaction might get committed > > > and freed via jbd2_journal_commit_transaction() -> > > > jbd2_journal_free_transaction(), when we release j_state_lock. > > > So check for journal->j_running_transaction everytime we release and > > > acquire j_state_lock to avoid use-after-free issue. > > > > > > Fixes: 4f98186848707f53 ("jbd2: refactor wait logic for transaction updates into a common function") > > > Reported-and-tested-by: syzbot+afa2ca5171d93e44b348@syzkaller.appspotmail.com > > > Signed-off-by: Ritesh Harjani > > > > Hi Ritesh, > > > > Looking at the refactor in the commit this fixes, I believe the same > > issue is present prior to the refactor, so this would apply before 5.17 > > as well. > > I've posted a backport for 4.9-4.19 and 5.4-5.16 to stable here: > > https://lore.kernel.org/stable/20220426182702.716304-1-samjonas@amazon.com/T/#t > > > > Please have a look and let me know if you agree. > > Actually the refactor was indeed the cause for use-after-free. The original > code in jbd2_journal_lock_updates() was like: > > /* Wait until there are no running updates */ > while (1) { > transaction_t *transaction = journal->j_running_transaction; > > if (!transaction) > break; > spin_lock(&transaction->t_handle_lock); > prepare_to_wait(&journal->j_wait_updates, &wait, > TASK_UNINTERRUPTIBLE); > if (!atomic_read(&transaction->t_updates)) { > spin_unlock(&transaction->t_handle_lock); > finish_wait(&journal->j_wait_updates, &wait); > break; > } > spin_unlock(&transaction->t_handle_lock); > write_unlock(&journal->j_state_lock); > schedule(); > finish_wait(&journal->j_wait_updates, &wait); > write_lock(&journal->j_state_lock); > } > > So you can see the code was indeed careful enough to not touch > t_handle_lock after sleeping. The code in jbd2_journal_commit_transaction() > did touch t_handle_lock but there it didn't matter because nobody else > besides the task running jbd2_journal_commit_transaction() can free the > transaction... > Right you are, I misinterpreted the interaction with jbd2_journal_commit_transaction(). Thanks for verifying, I'll follow up stable to disregard those backports. Cheers, Sam > Honza > -- > Jan Kara > SUSE Labs, CR