Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9347355rwp; Thu, 20 Jul 2023 03:40:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlF5fMOahIwF7OeB+c6P7p7s57DfUctV5tHR25PQ0y9E9OJMBHF55xc9irBSA1/WdoUwHg3I X-Received: by 2002:aa7:cf95:0:b0:51e:22dd:5e90 with SMTP id z21-20020aa7cf95000000b0051e22dd5e90mr4333709edx.4.1689849617380; Thu, 20 Jul 2023 03:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689849617; cv=none; d=google.com; s=arc-20160816; b=wuLQJlv6MQbMSwr4ZELic1SLRvlVPCIlGC4Eb1jq/jaeVQAOGJ8cWsE1kjnUoi0r0A tatC+dErAFC13/lbrA+A4GLlARZY6sanOwTYuFFcLThdYa9u1AH7ItyKmZ6VC8XNIo6t CtBIa/OW+NRqUdCkxqTOD0pjNMU9G8LXOE7+fdmrwxg2WYIyG6rkYXwM5+m62F+O2eVv 46yIVd8axQTNEgEIUb6DdsO7yfllN87mGMajYBJ+gyNytH1Rt4gKtSLsvtgQL+um798a fwSilANZY/XqZ2xH50nXSaiol2n6OqzEVBVcaUQ8ZL67dBnwXWAItxJCxWDz7ZGHdrXF kBug== 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:subject:cc:to:from:date:dkim-signature; bh=b/WAt2ko11CilJolgusZ/OdpYjV+EX3EkCvfXpZrr+s=; fh=3jGebMFaf4vBXV9KRlcZn94+G4EzZp2pAcJZ9XegCc0=; b=yZ5E+V0RYGy8NDBS3XU48X+lJypDEJqJfebviFJMdYiM1Z92hkmfQu0pNonqqExcpj HnPcCfGvKvdWLdR6u41o5uf1iCTKb0mBDn9i63aco44sF7bjDDEsSMjqRhnHB6nrYTEE a/9KIbqfThLDXHmejXkSCQZC2WtyEcjUCsXVTugvIYiOjLfpQi0WkpQ8q19PnLAII/po Ze0pGOYEVeGrWnMYJbOERCdx5/3VfO6nxY4hqdL2asdwwUxZfmVnBkExsLTWonChKQhA YXLNK4tDC9AQB+4/zOMq8dE8RW/yvrS+jfwEgxZEKgTy3IlbT+gmLiSxZjodJEbCclGW iIig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=rYM95cPg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020aa7c3c1000000b0051ddbdeb0c7si616823edr.350.2023.07.20.03.39.52; Thu, 20 Jul 2023 03:40:17 -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=@suse.com header.s=susede1 header.b=rYM95cPg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbjGTJ4a (ORCPT + 99 others); Thu, 20 Jul 2023 05:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjGTJ42 (ORCPT ); Thu, 20 Jul 2023 05:56:28 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C8C213E for ; Thu, 20 Jul 2023 02:56:26 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0A75822B47; Thu, 20 Jul 2023 09:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1689846985; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=b/WAt2ko11CilJolgusZ/OdpYjV+EX3EkCvfXpZrr+s=; b=rYM95cPglHk9jDNfuHASRTtJqM/HIqnacVgIXmHuxF4ODF6cin0kf8fTvWqt6glaITqfuy 7+RzwU9B0mJDUrMkqT64sKEfgPT1Dod0laGPnAG/mMbq2gCiy9Ke+G7gEGBRbVuz5RaeCw yAuwOjCRnfVMyzo1MI8oU4a5/yqlvJ4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D4A08138EC; Thu, 20 Jul 2023 09:56:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YmAUM8gEuWQIVQAAMHmgww (envelope-from ); Thu, 20 Jul 2023 09:56:24 +0000 Date: Thu, 20 Jul 2023 11:56:23 +0200 From: Michal =?utf-8?Q?Koutn=C3=BD?= To: Zheng Wang Cc: shaggy@kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, security@kernel.org Subject: Re: [PATCH] fs/jfs: Add a mutex named txEnd_lmLogClose_mutex to prevent a race condition between txEnd and lmLogClose functions Message-ID: References: <20230515095956.17898-1-zyytlz.wz@163.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="jkju3j6sdz2snaei" Content-Disposition: inline In-Reply-To: <20230515095956.17898-1-zyytlz.wz@163.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 --jkju3j6sdz2snaei Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Zheng. On Mon, May 15, 2023 at 05:59:56PM +0800, Zheng Wang wr= ote: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > BUG: KASAN: slab-use-after-free in instrument_atomic_write include/linux/= instrumented.h:87 [inline] > BUG: KASAN: slab-use-after-free in clear_bit include/asm-generic/bitops/i= nstrumented-atomic.h:41 [inline] > BUG: KASAN: slab-use-after-free in txEnd+0x2a3/0x5a0 fs/jfs/jfs_txnmgr.c:= 535 > Write of size 8 at addr ffff888021bee840 by task jfsCommit/130 >=20 > CPU: 3 PID: 130 Comm: jfsCommit Not tainted 6.3.0-rc7-pasta #1 Is this still pertinent with the current mainline? (There were some changes to jfs.) > Through analysis, it was found that a race condition occurred between two > functions lmLogClose and txEnd, which were executed in different threads. > The possible sequence is as follows: >=20 > ------------------------------------------------------------------------- > cpu1(free thread) | cpu2(use thread) > ------------------------------------------------------------------------- > lmLogClose | txEnd > | log =3D JFS_SBI(tblk->sb)->log; > sbi->log =3D NULL; | > kfree(log); [1] free log | > | clear_bit(log_FLUSH, &log->flag); [2] U= AF That looks sane to a by-passer. > Fix it by add a mutex lock between lmLogClose and txEnd: It doesn't feel right wrt "lock data, not code" heuristics. And when I apply that, it turns out there's already jfs_log_mutex. I'd suggest you explain more why a new lock is needed (if that's the preferred solutino). Thanks, Michal --jkju3j6sdz2snaei Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQpEWyjXuwGT2dDBqAGvrMr/1gcjgUCZLkExgAKCRAGvrMr/1gc jgMiAQDiHc2GPqN8BEsMex2H34eKF9kt0wtLtDPBjnRrVmd8ygEA43Tu18sFH+MU p0UqiCSAchUq85Mzs0XfmVLFFOAmXAU= =Toyw -----END PGP SIGNATURE----- --jkju3j6sdz2snaei--