Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp808380ybj; Tue, 5 May 2020 07:52:02 -0700 (PDT) X-Google-Smtp-Source: APiQypKfrwiMSuulKFwVbyzJZhasul+uwDgQZo2wyWxj+qh4D+QM3wPQ5nIX83QDHZxRkp0liUoY X-Received: by 2002:aa7:c401:: with SMTP id j1mr2933008edq.31.1588690322475; Tue, 05 May 2020 07:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588690322; cv=none; d=google.com; s=arc-20160816; b=AOTmG96KgFUm5fq+VbTZQ4INB6d4q9oUnAKkr0KS3WkxJkg9J4xpApwMh+0GS2CT1K +OuSVwPqL+hXzL3EpacW7fhWA0RhOtWcgaUJfu/3iHf4tVBMrhomElCJiekZFi7YyLeT 1QHkqNeg6mHIVutTtPGjqUs6myPUeOHY7T6Vin3e3vMRwh/s10f8Mwj/DSoMHb/jlbRj WH70JskqiUvCv1nQDADIKHeZPAFCEOr6KvlEERfiXARwa8DKQsobmPMLYDFEzN/j4ZWs vNUH5nZkJoKShAPY6bwVyTB4f9bCDLHZOCoxXvcw39QkaYRii3bYgmd3CIolQHkcsfua C6yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=FHjXPsU26H0OF2JRAex/ddIqer39oiBwJgvFSKTEKIY=; b=b0ZIxSAlwWPAnUkhWFzo+sSfqNqdIWMd0P4X9m0gg+V8w6WDgPwqhsHPALhyRCmMI7 GWzH4qieGw6H95V7djEqTerIn2fj5WynL2QQ5EcbDoCA7a8Ps42p1ULY7yu7oH0zKa8i VptBwf6Fe4ur8bYdXw3m0D7VAUobhnu3YIYbzWryJ9ktzBEpp5gHocT4VcUB9TJ97OWR m/Tuz0s8KDDHVm8Oz7QhjVpUue5T9jT0C/sMBomosXNiPl4xne5YvIsjFSw21u7fvY1B 1j4sw+ycLmZm9Kg4i1YAkVu/NYMqDedouPmuSanXP7emohMLGcuWp22zyfB5jAtlqj1A MN+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=loAfKpvr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w18si1302704edr.474.2020.05.05.07.51.39; Tue, 05 May 2020 07:52:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=loAfKpvr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729345AbgEEOuF (ORCPT + 99 others); Tue, 5 May 2020 10:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729060AbgEEOuF (ORCPT ); Tue, 5 May 2020 10:50:05 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D39C061A0F for ; Tue, 5 May 2020 07:50:03 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id q24so469432pjd.1 for ; Tue, 05 May 2020 07:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=FHjXPsU26H0OF2JRAex/ddIqer39oiBwJgvFSKTEKIY=; b=loAfKpvrXy8JZk/co9QVvVYUvjTD5FZP/X51udmNZb9CVrPWUPLJjgkVeX4yzMNuos i4s9co+v9pPLXg7fiTwT8CjSc7DvVUck2Pw5Il4WWHdId9tQN417sNnw+0dnKWo/srlQ tCcXviaPvUcA2ReZgq+YemUOsAIppGo9k+H+EGZmfugrabUOZD8RZDeKTvWEKHTvciss OXYim4bYgvD2sSoUH99mEJ4Rr0zPYRIbmMTpXm7a2M2P/s3ukqKIgrE3KS2mDbf06dt3 IJQYwsmGwUj1njTjH9KNy5V9q+ZVw39HViCX6XuXZ20ONqc4h3HKcCv2FfRS+Xpc0TNr GcYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FHjXPsU26H0OF2JRAex/ddIqer39oiBwJgvFSKTEKIY=; b=IxFXZM6Cjm21Xw7uFh9lEwMfS/eFwXvMfuNLIjAXDggHYjEMCxOgBGW2R2iCz5PpRL 6pX5Tgr21/KjeQTvwNui/PUpXR7Qg0ems96zi/DpK35Syg8+iUm5qvnYZSCmYgpOaiJj NfPk2g6ruPtOtHQbe8NlY+eS9wpvR9WBo7F0T7ZbzYSzwCLjfmn7o5ZgArOLO8S8Gxqa P9h3Mr8UdYRDdnVTO4vEcSE+07gv11CE3kQDfwnk3bM8rSwE1UUoujrlK6w5jXV3JWly FzPZ9Cd89Uq9iiU4qrS66nC0kxaUK+nfAQ0st71zuGzdO2dcQOFwAN/1K5+84PjszzLh 5q7g== X-Gm-Message-State: AGi0Pua15sJWDcvp8NUntqTQxsPec6u1UXtqTexlvne8EvbsJe3k2AKD A1ay5qrRKvMWx60LiunJK8c5xue+5BUN0Q== X-Received: by 2002:a17:90a:2645:: with SMTP id l63mr3610638pje.54.1588690202879; Tue, 05 May 2020 07:50:02 -0700 (PDT) Received: from localhost.localdomain ([120.244.110.63]) by smtp.gmail.com with ESMTPSA id c84sm2288400pfb.153.2020.05.05.07.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 07:50:02 -0700 (PDT) From: Jia-Ju Bai To: shaggy@kernel.org, Markus.Elfring@web.de Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH v2] fs: jfs: fix a possible data race in metapage_writepage() Date: Tue, 5 May 2020 22:49:30 +0800 Message-Id: <20200505144930.7990-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The functions metapage_writepage() and lmPostGC() can be concurrently executed in the following call contexts: Thread1: metapage_writepage() Thread2: lbmIODone() lmPostGC() In metapage_writepage(): if (mp->log && !(mp->log->cflag & logGC_PAGEOUT)) In lmPostGC(): spin_lock_irqsave(&log->gclock, flags); ... log->cflag &= ~logGC_PAGEOUT ... spin_unlock_irqrestore(&log->gclock, flags); The memory addresses of mp->log->cflag and log->cflag can be identical, and thus a data race can occur. This data race was found by our concurrency fuzzer. Thus use the spin lock "mp->log->gclock" for the assignment of the data structure member "log->cflag" to a local variable in this function implementation. Signed-off-by: Jia-Ju Bai --- v2: * Change the description. Thank Markus Elfring for good advice. fs/jfs/jfs_metapage.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c index a2f5338a5ea1..026c11b2572d 100644 --- a/fs/jfs/jfs_metapage.c +++ b/fs/jfs/jfs_metapage.c @@ -351,6 +351,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) unsigned long bio_offset = 0; int offset; int bad_blocks = 0; + uint cflag; page_start = (sector_t)page->index << (PAGE_SHIFT - inode->i_blkbits); @@ -370,8 +371,14 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) * Make sure this page isn't blocked indefinitely. * If the journal isn't undergoing I/O, push it */ - if (mp->log && !(mp->log->cflag & logGC_PAGEOUT)) - jfs_flush_journal(mp->log, 0); + + if (mp->log) { + spin_lock_irq(&mp->log->gclock); + cflag = mp->log->cflag; + spin_unlock_irq(&mp->log->gclock); + if (!(cflag & logGC_PAGEOUT)) + jfs_flush_journal(mp->log, 0); + } continue; } -- 2.17.1