Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10591264rwp; Fri, 21 Jul 2023 01:28:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlFWvMRvdiK7EO5ZUhmgi9EzIo4FxbSRf8i9193FUa6xQ++lW897Uvt9UEd3eG3hWmpafjL3 X-Received: by 2002:a05:6a00:2354:b0:668:7209:1856 with SMTP id j20-20020a056a00235400b0066872091856mr1254996pfj.14.1689928131576; Fri, 21 Jul 2023 01:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689928131; cv=none; d=google.com; s=arc-20160816; b=q5TcXg+/XO6c1sfweWJDoo9TQszl0XytITkHm7TknCZ5UlAMLBjJeR0jC4NpfdBqqh GI5uWPzoAJKhrrpEX/Oarukk/PG78R6KawjTuQhE7Fs4Orm8fuE2xZeaZDRmmmpQkOXc 6ZHbxvp4X0yv58E+HOMr+fyEUvJmm1uTEjIVv2AuLmhwFArnrSLLBDPXwQM5I8LRSzY2 8GMRjgV6qtBz1giFFdkpGEFBcJq9fPz3BpB0EMo01Wl4b2ClsIn8r+IhtNhqVnlM5HgA d3ekA6dW8lOQdBxBb/Fz/pr1sK7DJfbIeTF3+306X1YNBYkFeW8XsWXE7ZKvEkFQ5jdB Q5bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pd2HhKZxSyoZydvli66d5N9UqG8GWNvUPymvOuFu+BY=; fh=9coCqDZ/oNGYf/Jzv81QTRTxvU9atoSB+FY//GoSkvQ=; b=ZJXMBXm4HsvJwuHklXsrlOKG8fZEgBpkKCMhNloUpokIo1Tkaxh6FHnmGTJPheTb8l ShGYupsi0gjyQkNKq0jFPXDzKqADTyQjMrokduyKLj/7WknpdJYtH6hBYG0TifmlJz/v Fk+x7F7XLslBH7y+D/BRWcMRQ69BdMUjAou7HzQjPedGGHIDPswFrkE2wzvormY9SSeS pamFHYdTGWqCgpVt5XBdb0gvcYAdCtV6oZZXFP+ipu823EltAK4Lro49z2SP4c0sHg2O R6A9b2s/Bhpi0ZwUq08t3o6lbiQ36erB9XcrnnrlNH1anZUWdyleYbgNd0o6j1yn3gdt lzoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WrqNWxA6; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fc6-20020a056a002e0600b0068661fafe90si1259060pfb.253.2023.07.21.01.28.39; Fri, 21 Jul 2023 01:28:51 -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=@gmail.com header.s=20221208 header.b=WrqNWxA6; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbjGUIPe (ORCPT + 99 others); Fri, 21 Jul 2023 04:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231444AbjGUIPd (ORCPT ); Fri, 21 Jul 2023 04:15:33 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39DE4270A for ; Fri, 21 Jul 2023 01:15:31 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-263121cd04eso894248a91.2 for ; Fri, 21 Jul 2023 01:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689927331; x=1690532131; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pd2HhKZxSyoZydvli66d5N9UqG8GWNvUPymvOuFu+BY=; b=WrqNWxA6ozYcj57TebNYbv3CyPO4HiaeGg8dhFmCNz2fu3TAP3T7amvGX2pGp3cOZk 0mv7FhbktJWEcOEpBX8bx85ELIypT5ZslXmYriWWqWV/DK3thkXFHcupNZL7CCnEtGh2 0b5BrMeVMnT8MhHGYtLLTW2LyuvDpptlTQ6hOCRJYaiH7MbaOt0wu3Ty8M5gT+4BxJ15 OmysFFZhihSq/aQQVdCiBHAa0gWsvdQetNvzA+1eekZ8tJsU7kKoj6Fu2OJXFnTtY6s+ E8pkbfOrvGplHvCVGaQe4RVURpfq9qeyCDvpQgQIMtAFE2vIDspDQ3j2B8ydhek++41s 3/Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689927331; x=1690532131; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pd2HhKZxSyoZydvli66d5N9UqG8GWNvUPymvOuFu+BY=; b=bqe/RWNu71v3o/pVwkdv8HWx0seCPLp/MxKH6foUDsIWesO/Mdkc7flkZ1aFa/vQ/Z SbNu0Bb/rAwMBQ1V+Gv2B1TPWPWRXbe+aFT+OXQyb8Q6wHtluW3HEDuuj0ujAo1eKSZy s+tOgLhC2w7J2j6L5MUhj/Y20l7LOtP6pusd2LtciPq88SAHQ32JeODuJPMhz6qXNi69 xsSYs24HDIW3YdAlqtt6XLWF+zMSkcSUxrypoD5uooQx3hATeiAnPjVuM5LBr2oldSLI 9KH63zJcpdR6AVtqJGLhlU0z1ASiqElptB9BZPiPp0oe1h8Np/Z9WdzZgt7b5FK+drTA w2Eg== X-Gm-Message-State: ABy/qLbtcmWwzF8BMtghecZzdLp+BdditvIhQY+FGFcvzBZEd80UJnPh mb4Sanjr59nYGp2IPl/Kq8LB2sRnyE2hnFCza+Q= X-Received: by 2002:a17:90a:d711:b0:263:5c78:4b63 with SMTP id y17-20020a17090ad71100b002635c784b63mr779192pju.45.1689927330568; Fri, 21 Jul 2023 01:15:30 -0700 (PDT) MIME-Version: 1.0 References: <20230515095956.17898-1-zyytlz.wz@163.com> In-Reply-To: From: Zheng Hacker Date: Fri, 21 Jul 2023 16:15:19 +0800 Message-ID: Subject: Re: [PATCH] fs/jfs: Add a mutex named txEnd_lmLogClose_mutex to prevent a race condition between txEnd and lmLogClose functions To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Zheng Wang , shaggy@kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, 1395428693sheep@gmail.com, alex000young@gmail.com, security@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,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 Hello Michal, Michal Koutn=C3=BD =E4=BA=8E2023=E5=B9=B47=E6=9C=8820=E6= =97=A5=E5=91=A8=E5=9B=9B 17:56=E5=86=99=E9=81=93=EF=BC=9A > > Hello Zheng. > > On Mon, May 15, 2023 at 05:59:56PM +0800, Zheng Wang = wrote: > > =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/linu= x/instrumented.h:87 [inline] > > BUG: KASAN: slab-use-after-free in clear_bit include/asm-generic/bitops= /instrumented-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 > > > > 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.) Thank you very much for your reply and suggestion. I thought that this BUG still exists in the current mainline kernel version. Since I am not very familiar with this part of the code, I am not sure if the proposed fix is correct. > > > Through analysis, it was found that a race condition occurred between t= wo > > functions lmLogClose and txEnd, which were executed in different thread= s. > > The possible sequence is as follows: > > > > -----------------------------------------------------------------------= -- > > 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]= UAF > > 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). You're right, I think my fix method is not a good solution. Hoping you and other developers can help fix it. > > Thanks, > Michal Once again, I appreciate your help and will take your feedback into consideration when working on a solution. Best regards, Zheng