Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp379414imm; Thu, 30 Aug 2018 00:52:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbbH98OgTmiBLpxxNUMDLeI0VXPaoBN1OAZIQaaMIUXfoLTN3Re875/4As304IYXBk0jwS/ X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr8894873pgv.52.1535615546411; Thu, 30 Aug 2018 00:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535615546; cv=none; d=google.com; s=arc-20160816; b=S0qgMZezv4eft35s+v6Thz+EZ35x3T1+s4Ciz91wniw5x0X6AMy2ys8i/jyxqBEaCh pwt9sk/3VcmCI0oH/fE0CLZ03JSwdIkPnbqf4SyNCkE7wb2RbfecgYOLcR3lIr/m4Jwq 2jVjkeSy0SapdjC2hZ3Jlnd/rWK4dXesmtPFc0J0vMFcTnE/IjMG0ViGB+7xvIuM4LnI SQv3KCelT4QG7p/S0A2FxvgLci+NwVoXtDWT9ejrMUmKtGSXjIfUom95mghq44h7HVy7 rhzdSe7AHqZOYxRBpKsNqTWInvAQT4c1QImI7jEyuPuzO44zolr09cXytQvmEhh5U+rw uNEg== 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 :arc-authentication-results; bh=h2gLgHfqz7F16k3G+7spO/ItclFFSSP5UUMAAe1AL1Y=; b=tevYiXkFfVd0daqnnkogU1Me00n7VPCB312lhhS99RXZAgH3CRLw/WTvpS8yJ276yK XpmtUXG18z5Mnz+pwY9Nw2qdGoErvgB+5BCMnNG1xrpd+3KnbiADMYN+NwhsskccVZzH Fw5O0CP7/kwhco2Xgc/aa6swxxf7KYtlHYQFRCKmwntQwYD5KliruX/zaRknvrMaO7jq HorrzxN+u7ccn5DQ/t4WBjlKIhu5xIiYuaRYXYqrULzMlcG7re9Z5rk5Ndmu7Vxw5Bmz HIRPB4ZDKBNeqT6+TJv64tXaMxufztYk2sjcZ5QTREDsn4ndviXmBjlBSEUd2B+lVxqE Oqxg== 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 v188-v6si5735608pgb.96.2018.08.30.00.52.11; Thu, 30 Aug 2018 00:52:26 -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 S1727681AbeH3Lvt (ORCPT + 99 others); Thu, 30 Aug 2018 07:51:49 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:38894 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727203AbeH3Lvt (ORCPT ); Thu, 30 Aug 2018 07:51:49 -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, 30 Aug 2018 01:50:50 -0600 From: Larry Chen To: mark@fasheh.com, jlbec@evilplan.org Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, akpm@linux-foundation.org Subject: [PATCH V5] ocfs2: fix crash on ocfs2_duplicate_clusters_by_page Date: Thu, 30 Aug 2018 15:50:41 +0800 Message-Id: <20180830075041.14879-1-lchen@suse.com> X-Mailer: git-send-email 2.13.7 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 one of extent's pages is dirty. When a page has not been written back, it is still in dirty state. If ocfs2_duplicate_clusters_by_page is called against the dirty page, the crash happens. To fix this bug, we can write back the page rather than just wait. The following is the back trace dump: kernel BUG at /root/code/ocfs2/refcounttree.c:2961! BUG_ON(PageDirty(page)); [exception RIP: ocfs2_duplicate_clusters_by_page+822] __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 Change-log: 1. Once we find the page is dirty, we do not wait until it's clean, but rather we use write_one_page to write it back 2. write_one_page arguments list changed, adjust and retest this patch. 3. Comments has been changed 4. Sorry, miss "ocfs2" prefix in patch title Signed-off-by: Larry Chen --- fs/ocfs2/refcounttree.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 7869622af22a..ed84d05c7d00 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; @@ -2954,11 +2955,18 @@ 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. + * In case PAGE_SIZE <= CLUSTER_SIZE, we do not expect a dirty page, + * so write it back. */ - if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) - BUG_ON(PageDirty(page)); + if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) { + if (PageDirty(page)) { + /* + * write_on_page will unlock the page on return + */ + ret = write_one_page(page); + goto retry; + } + } if (!PageUptodate(page)) { ret = block_read_full_page(page, ocfs2_get_block); -- 2.13.7