Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3731573ybz; Mon, 4 May 2020 08:40:34 -0700 (PDT) X-Google-Smtp-Source: APiQypLQ/8PUBnOHYcq6WlMP43qMohCTSzpWIYgDBq55866vwRmkvfSooMHV4mwgSN/+Qib23GXR X-Received: by 2002:a17:906:328f:: with SMTP id 15mr16150809ejw.33.1588606834398; Mon, 04 May 2020 08:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588606834; cv=none; d=google.com; s=arc-20160816; b=lg4gd8xtcOyQSygh63TsHistBftguToLp3U1XVkjjJEeoxuSv9yQUohz9mXfXWcvGW np74aKnLWVdGPlsTIDylxYOHI5rGVFtfjqq69JPEbZPzkCfrxW4x+gwHrLRUlCEVCfuQ 0FUDXeQRd4sGvewmCZYvh6k2wZrxfRWyJX9plP6rRBNjnvxWxYLpmPf4Q5GaglXbRWKG 3pXpFx4yrUIXzv6cYFW2rLW7ggy5s5QxC4xX2L6gc+CTdXA5jKYUn8/7ZM1KB5RTbaq9 8yYQ/l8UIlSKH+VHi7mha3bYsZnVf9x9T2qdALUs3eTpWFvb570ANanADLAGraR10tD+ yP4Q== 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=MttICuxXavbYMq8WIjicbuvf1Y6ye3X+bWJxx0AAnXc=; b=GmS9269kog0fwRaZTKDymmgLV/uAtGpOi1wJvSTJMvOwlUlHLwbn5bp9lIfU3ghf3X 2CyNLRS7d66NcYTd0FKGCmf3m6vFS/CuaGPjlsVKVZsp6u/3heX3lGRxEscGW5Jsb9oj O0/AO+h22JH5weEvMjXNbjMvQOpiz8LQbiQnjQlZPILileNP/kr74leCGcTjyKaELdF6 N8XEg9KKsjXT54LqKF4/hkNrgYwz2ilrESvssIWek+Ugp518qP+4iTDQUbAeVPY11z3B 42Hex2q4IVzBR8FmL5PP0Ex7ckZQO5/HqErhgfZfE+IH7n/OeshDhZyZYz7WrwVVfP9N iwAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GITI6WzH; 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 v24si6483625edx.606.2020.05.04.08.40.09; Mon, 04 May 2020 08:40:34 -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=GITI6WzH; 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 S1729414AbgEDPeh (ORCPT + 99 others); Mon, 4 May 2020 11:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726509AbgEDPeh (ORCPT ); Mon, 4 May 2020 11:34:37 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39766C061A0E for ; Mon, 4 May 2020 08:34:37 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id q124so8599020pgq.13 for ; Mon, 04 May 2020 08:34:37 -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=MttICuxXavbYMq8WIjicbuvf1Y6ye3X+bWJxx0AAnXc=; b=GITI6WzHQ8sPVvnvNjM/77u08qgAq7eXKr1ZaNlw2etpk+K0D2RIl+nt2Lm77+qcp+ WT2VCckI36iyFh/n8nGxdzrNp1gUGTzjtjJT4tY6Ko36IvJZsAkM/5vnNjvSbVf9LaY7 DUccfi+2/Zf2VjUl8GIMQCaAHtBb1N/u3mL7rD9CgeB9QA7rKNYFhrNzmttYAW1tGQ2c wr9SK36Ap5IDTURoTjocTnJfqz4YlSt8L62ieB+NXzXqGVuPAPdHkPtqcJoJUaiTR5oE +o2yVX7s5M4PUNdc5bqReRhkodBRSfxoVorAVIJUmNEMq75zMns/Panug5Tr+3cxf+Ya FjKQ== 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=MttICuxXavbYMq8WIjicbuvf1Y6ye3X+bWJxx0AAnXc=; b=cA2LxR7FCwC3biK7DhkowLM78SE0Kb85yQZZQggTwvgCKms0B8Exl8dR3ZeMlahp6z a2xxwu6mXAxvIO3WTGF53iuUqDZ6OHJfbU/LHv8aGKN1CzXPYm8LR2r8Exdpn2y6mOdl ryIGwmMPdrsHtYsMK7KtPZeu5eBwe6YOZCBY465DVpTiF9LDoQLv7EzWa3r6ZOsyaozk qlY0IqtWdI7RRcXtHlDQQ+oDElwWbxeFU9uKGwfV/9lAwDGfrvNOxCXXvJxGRpXocK7j lC3KZB3OfOv0ghdpwrmQkkUebp1rigFdcqRMM8qqhK/yiH6RNhcEOZ1sDnMEOCtKxkpS UthQ== X-Gm-Message-State: AGi0PuaNrLGwv3eKUnyebS8avrMHG+Bv1rkB4Xp1wrAR6/b5F66YNuJg mjVZwm4sYnqnJbP2bg2JhBc= X-Received: by 2002:a65:6713:: with SMTP id u19mr1438519pgf.143.1588606476815; Mon, 04 May 2020 08:34:36 -0700 (PDT) Received: from localhost.localdomain ([120.244.110.63]) by smtp.gmail.com with ESMTPSA id c4sm7178830pga.73.2020.05.04.08.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 08:34:36 -0700 (PDT) From: Jia-Ju Bai To: shaggy@kernel.org Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] fs: jfs: fix a possible data race in txBegin() Date: Mon, 4 May 2020 23:34:11 +0800 Message-Id: <20200504153411.13679-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 txBegin() and txLazyCommit() can be concurrently executed in the following call contexts: Thread1: jfs_write_inode() jfs_commit_inode() txBegin() Thread2: jfs_lazycommit() txLazyCommit() In txBegin(): tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0; In txLazyCommit(): spin_lock_irq(&log->gclock); ... tblk->flag |= tblkGC_COMMITTED; ... spin_unlock_irq(&log->gclock); Thus, a data race can occur for tblk->flag. To fix this data race, the spinlock log->gclock is used in txBegin(). This data race is found by our concurrency fuzzer. Signed-off-by: Jia-Ju Bai --- fs/jfs/jfs_txnmgr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index c8ce7f1bc594..a1f124aad2e0 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c @@ -415,7 +415,9 @@ tid_t txBegin(struct super_block *sb, int flag) * * memset(tblk, 0, sizeof(struct tblock)); */ + spin_lock_irq(&log->gclock); tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0; + spin_unlock_irq(&log->gclock); tblk->sb = sb; ++log->logtid; -- 2.17.1