Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2289281rwi; Fri, 28 Oct 2022 05:28:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qJvau7NXrHseubNyFxmWTgf5dLpV5510fD0cYt7194JetYzXMxe5GmUTo725W+yVvbb1B X-Received: by 2002:a17:907:7f1c:b0:78d:ddc7:dfb1 with SMTP id qf28-20020a1709077f1c00b0078dddc7dfb1mr48346020ejc.189.1666960102734; Fri, 28 Oct 2022 05:28:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666960102; cv=none; d=google.com; s=arc-20160816; b=P1C24RRcxWN1IpTMeVM4eLFyrC+FshnVqmvWs/eusQVcLQx0mBnFuP8cvx0fQXIMTl pBpYoqiMBoSz8zy6pZGI46CWfO+jvjki0QNYWz4Pc6KjcfOneCSwtWoe2uS/mroTS9be XwRQXoyZJqvVKu3sdUrECeK10w/4h785L13RNwQUYHejkTjj09lzJw/GHMZNqxVtsvfD rnfLvjlVuidZekkNl3lDjqIlLDx2bJubkuonhk7e/XfH7RN31YM8Kd3JmiXlFF6UKM1+ jU4RW2MZCVvZjLvYNVsECwtGsGk6hQJENBEOAWAaBGlLjW63c1Thl6cqi6089FRuwDtN XCZQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=fkNyqRiedTm3lH/AVehxw07LQ3B/+YJMsP8sTlhH3nE=; b=DmFeSj7z397K6lADNsapmJ+mR1Zr5PI6aE7hTcAr9zJ789RTiMa9Md0A85k+Je0W32 Hjh0HRdkytEXBlc0y1wlNsnRrNnDaFKHJaVebA2akc6aDyFQJ6+sVwTODQDRqWC1NqBv ahCpqxm5n5B9p3gjZEm4KBC3doETxmOf3q0Y3UWQklP3dOFODN+ddbZrfi10aoiFDo41 RdBBXRzlEmHjdHj8vdXx9M/lj0PtLaiU3cAm367sill8Tf7uHEjJSAkNwQn+qOyx3cVc EdOWeXMeZ0WXkUBk06MhZqOr75v8lqQR0r9iNo4B8YBJo9UbVYT67lkaOq2ZOI1lHyK3 YBvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gRJ4praD; 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 f24-20020a50a6d8000000b0045bd55b122fsi1611767edc.57.2022.10.28.05.27.56; Fri, 28 Oct 2022 05:28:22 -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=20210112 header.b=gRJ4praD; 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 S229642AbiJ1MYj (ORCPT + 99 others); Fri, 28 Oct 2022 08:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbiJ1MYh (ORCPT ); Fri, 28 Oct 2022 08:24:37 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F12F60EF for ; Fri, 28 Oct 2022 05:24:27 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id o12so7989858lfq.9 for ; Fri, 28 Oct 2022 05:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fkNyqRiedTm3lH/AVehxw07LQ3B/+YJMsP8sTlhH3nE=; b=gRJ4praDAGw8E8zTwBp3rS9xfPk35V676mB/QeOxwyzopxEGteUPw9sAoLNXIZcgf9 jYn1MJrjYBTGJsHpplB7gyPOGRQmuNahGxrApoE5EVDGy8vR2vjaRn7Sc+17KWyDI/D1 QE7bX1McwmZpoHKNlL4Gj19GfK96ecrbnsK3Umt+aKDeEDJSVjvQAaCY5f+a7X8cwLVk /4w2zQ7SYWMSC1EU7AYWfQbkg10qvQqWSy6apCUNGinuTSHph6/Q2VpukkjMiBPEdgPK DzCLekHmldZ4N14x04bFscTVIcDtRa5SQROZT3XbBZ2oJCD+C00xk4qbSofI8nbWT3uw 3vCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fkNyqRiedTm3lH/AVehxw07LQ3B/+YJMsP8sTlhH3nE=; b=6lD1WWS102YDnQlpz1g1OzlSvw//cqOmcPSISdU7VClHsyRI19ITQz3IhOjxtvnd1A oTG3SZCOs40l9ZHina9LuUPYuUpWTAgiSJBN3J9FDpaRCQDUQgkSjoyVf9INzlXsf1QZ hdnrW/jTXBjv5BGHxiSSLlNm1EZpAov04t8v7Q1xgK4DXuIA4I40X41DjZo5r4ouISfK WWz5mvfgu5lio7ZfPkwIvFlY8cOGn3UdNowtgq+eNnkErk303UxF6bGe+N/aoki9C1FW G1J1JeL5eqMRaFoUv4sP+Pa3GbOI4xond2m6KSKiv6GxGs8v/FHPK3eu+73VAYHP8ECd l62A== X-Gm-Message-State: ACrzQf3DBKg8VfX07dLu//6I3ZAtLvkIm/kSV0Gm+9KiaXqtnuw3t0YQ xp+3Rof9dJqKZDSQroWf0X0= X-Received: by 2002:a05:6512:3085:b0:4a2:7d80:d4b4 with SMTP id z5-20020a056512308500b004a27d80d4b4mr21397278lfd.534.1666959865943; Fri, 28 Oct 2022 05:24:25 -0700 (PDT) Received: from localhost.localdomain ([95.79.189.126]) by smtp.gmail.com with ESMTPSA id x16-20020a056512079000b00498f871f33fsm546686lfr.86.2022.10.28.05.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 05:24:25 -0700 (PDT) From: Oleg Kanatov X-Google-Original-From: Oleg Kanatov To: Dave Kleikamp Cc: Oleg Kanatov , jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Oleg Kanatov Subject: [PATCH] jfs: makes diUnmount/diMount in jfs_mount_rw atomic Date: Fri, 28 Oct 2022 15:22:54 +0300 Message-Id: <20221028122254.21081-1-okanatov@astralinux.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 jfs_mount_rw can call diUnmount and then diMount. These calls change the imap pointer. In case JFS filesystem is mounted on root (/), between these two calls there may be calls of function jfs_lookup(). The jfs_lookup() function calls jfs_iget(), which, in its turn, calls diRead(). The latter references the imap pointer. That may cause diRead() to refer to a pointer "freed" in diUnmount(). This commit makes calls diUnmount()/diMount() be atomic so that nothing will read the imap pointer until the whole remount is completed. Signed-off-by: Oleg Kanatov --- fs/jfs/jfs_imap.c | 2 +- fs/jfs/jfs_mount.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c index 799d3837e7c2..390cbfce391f 100644 --- a/fs/jfs/jfs_imap.c +++ b/fs/jfs/jfs_imap.c @@ -310,8 +310,8 @@ int diRead(struct inode *ip) iagno = INOTOIAG(ip->i_ino); /* read the iag */ - imap = JFS_IP(ipimap)->i_imap; IREAD_LOCK(ipimap, RDWRLOCK_IMAP); + imap = JFS_IP(ipimap)->i_imap; rc = diIAGRead(imap, iagno, &mp); IREAD_UNLOCK(ipimap); if (rc) { diff --git a/fs/jfs/jfs_mount.c b/fs/jfs/jfs_mount.c index 48d1f70f786c..972b9ff18723 100644 --- a/fs/jfs/jfs_mount.c +++ b/fs/jfs/jfs_mount.c @@ -234,12 +234,18 @@ int jfs_mount_rw(struct super_block *sb, int remount) truncate_inode_pages(sbi->ipimap->i_mapping, 0); truncate_inode_pages(sbi->ipbmap->i_mapping, 0); + + IWRITE_LOCK(sbi->ipimap, RDWRLOCK_IMAP); + diUnmount(sbi->ipimap, 1); if ((rc = diMount(sbi->ipimap))) { + IWRITE_UNLOCK(sbi->ipimap); jfs_err("jfs_mount_rw: diMount failed!"); return rc; } + IWRITE_UNLOCK(sbi->ipimap); + dbUnmount(sbi->ipbmap, 1); if ((rc = dbMount(sbi->ipbmap))) { jfs_err("jfs_mount_rw: dbMount failed!"); -- 2.30.2