Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2526726imm; Thu, 16 Aug 2018 10:55:36 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzCFfIXkgLEDPs61oq/r/mKDIkDwzi+pA+N+X9xkYTQabpmmGOg7ijVQ9YEUAbfrIrp3Jyc X-Received: by 2002:a17:902:3225:: with SMTP id y34-v6mr14895999plb.206.1534442136944; Thu, 16 Aug 2018 10:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534442136; cv=none; d=google.com; s=arc-20160816; b=hKjr8ck67ykP/GtVrrwmJXnWmsdB5doQtzyET/E+TZWzFAe2Eu/IBzcdgkKNQe3Zax EwPIzXk30Z/saj9srNydswu2+OzM68IpK8+sPlGjKOuYMZr7MP2i5Q53VQmbwU1FxlVc LBsSvtHsNiBnU2pjszqypcszrr42JcGDYVXGutBGm3tyT6NH6j5oXrT9GhoOvsCzum0i M7T3OnLbF/kVBUKPwc8/VhOCiCLA4PwJR5ZzeJw66tUGwGPZcIfc2tljl0lrr6XgwGkG TRu6+qiCeFXVfK6+luFEsW0rpGiBv2r46X4F/im1XPByOkcd9PNZMg37dOjWGT0Q+VaC XoaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :arc-authentication-results; bh=3VFXQOLz4DiZyK/5zVBMkoErmkjbKX8dPhVOcdv8Uuc=; b=QQSvt1tb1kQRfA3MiKZ9Dc8p6j4to75wvENmB6QQdRd1E+NLF9zcs1zh3qdQCgNCRa NT07NvPRBE1+hF7DwV80LJuwoGbLbISutyFa1BsMx6EHcsmMaEh25vl/rO/GK6EBB9pl oIivGYOaXNm9PJXX71vZFFdfoXTGGVuj3e2ifWJi23y4PYLhiJrk8ldDSJudsJuZOYo4 bq1T/PAOdX8/HRW4vExq6gQmlD6zqk1xbSHR8Z8OEjAIEf74XJ4lOuPXCFn2NBI2iNev /5LoAIbrAnPBBhf8eoQlSxC2RMaL1UlmeZnnKP7YuUCatN9v5HuPqXIFoNvDipke28Bt H0Uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28-v6si25731852pgk.111.2018.08.16.10.55.21; Thu, 16 Aug 2018 10:55:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391204AbeHPORH (ORCPT + 99 others); Thu, 16 Aug 2018 10:17:07 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:33725 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726392AbeHPORH (ORCPT ); Thu, 16 Aug 2018 10:17:07 -0400 Received: from Beta.suse.asia (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Thu, 16 Aug 2018 05:19:02 -0600 From: Larry Chen Cc: linux-kernel@vger.kernel.org Subject: [PATCH] fix crash on ocfs2_duplicate_clusters_by_page Date: Thu, 16 Aug 2018 19:18:52 +0800 Message-Id: <20180816111852.11846-1-lchen@suse.com> X-Mailer: git-send-email 2.13.7 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ocfs2_duplicate_clusters_by_page may crash if an extent's page is dirty. When a page has not been written back, it is still in dirty state. If at that moment, ocfs2_duplicate_clusters_by_page is called against this page, the crash happens. To fix this bug, we can just unlock the page and wait the page until it's not dirty. I don't know whether the patch is appropriate, so I need comments, thanks. The following is the core dump: kernel BUG at /root/code/ocfs2/refcounttree.c:2961! __ocfs2_move_extent+0x80/0x450 [ocfs2] ? __ocfs2_claim_clusters+0x130/0x250 [ocfs2] ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2] __ocfs2_move_extents_range+0x2a4/0x470 [ocfs2] ocfs2_move_extents+0x180/0x3b0 [ocfs2] ? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2] ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2] ocfs2_ioctl+0x253/0x640 [ocfs2] do_vfs_ioctl+0x90/0x5f0 SyS_ioctl+0x74/0x80 do_syscall_64+0x74/0x140 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 To: mfasheh@versity.com, jlbec@evilplan.org Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, akpm@linux-foundation.org Signed-off-by: Larry Chen --- fs/ocfs2/refcounttree.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 7869622af22a..ee3b9dbbc310 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle, if (map_end & (PAGE_SIZE - 1)) to = map_end & (PAGE_SIZE - 1); +retry: page = find_or_create_page(mapping, page_index, GFP_NOFS); if (!page) { ret = -ENOMEM; @@ -2957,8 +2958,13 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle, * In case PAGE_SIZE <= CLUSTER_SIZE, This page * can't be dirtied before we CoW it out. */ - if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) - BUG_ON(PageDirty(page)); + if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) { + if (PageDirty(page)) { + unlock_page(page); + cond_resched(); + goto retry; + } + } if (!PageUptodate(page)) { ret = block_read_full_page(page, ocfs2_get_block); -- 2.13.7