From patchwork Mon Oct 1 09:52:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10621755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 072966CB for ; Mon, 1 Oct 2018 09:53:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC8B22853C for ; Mon, 1 Oct 2018 09:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE718286FF; Mon, 1 Oct 2018 09:53:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 734F52853C for ; Mon, 1 Oct 2018 09:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=FUgHw7TxdPn0a0Pztkc7K9NWWfEV3zioebjMwcnJ9GA=; b=DivTEPiWPaXh8N 9RyFYWHX5BLaI60WREZInAaJasElGrQ2n0eqPBRVwcedjDpoxg2tehxfnfiBnAjh/cIKdWfpodGlZ VYlbuAUbz6FFGfJlVTSaE1/PCbxi/Qrxn2XhmZN47K8rF9GMniZzrfYyua5/CVnMKCVsx/+l4RGJH zax9CxtcTVMQpcURijpChGaDDUuGyBNhYAgZt2zwmyov5MpLWO7qydomfD/VYUvS4EQLYwMZHI9Fc 6XtXbbduNRPyg3X1KB96bP/o7t26JqvSphcLyBq6DEyCmK5cHSKddKx9LETGGUqaPrAibdSOGByND HdqhxvfzoZuy+DOwVoGw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g6utM-00026d-4j; Mon, 01 Oct 2018 09:53:28 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g6utI-00025D-Sm for linux-mediatek@lists.infradead.org; Mon, 01 Oct 2018 09:53:26 +0000 X-UUID: 949f58c949fa4796a5dd25306c8ef0fc-20181001 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 76860920; Mon, 01 Oct 2018 17:53:03 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 1 Oct 2018 17:53:01 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 1 Oct 2018 17:53:01 +0800 From: To: Hugh Dickins Subject: [RFC/PATCH] mm/shmem: add a NULL pointer test to shmem_free_inode Date: Mon, 1 Oct 2018 17:52:55 +0800 Message-ID: <1538387575-28914-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181001_025325_053131_DC8ECF43 X-CRM114-Status: GOOD ( 11.32 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Miles Chen , linux-mediatek@lists.infradead.org, Mark Salyzyn Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miles Chen We noticed a kernel panic when unmounting tmpfs. It looks like a race condition in the following scenario: shmem_put_super() set sb->s_fs_info to NULL and shmem_evict_inode() tries to access sb->s_fs_info right after the sb->s_fs_info becomes NULL. CPU1 CPU2 work_pending work_pending do_notify_resume do_notify_resume ____fput task_work_run __fput __cleanup_mnt inotify_release cleanup_mnt fsnotify_destroy_group deactivate_super fsnotify_detach_group_marks deactivate_locked_super fsnotify_detach_mark kill_litter_super /* sb->s_fs_info = NULL */ iput evict /* use sb->s_fs_info */ Add a NULL pointer test in shmem_evict_inode(). We have stress-tested the patch for 5 days with no panic. Please note that this patch is a band-aid patch. VFS: Busy inodes after unmount of tmpfs. Self-destruct in 5 seconds. Have a nice day... [name:traps&]Internal error: Accessing user space memory outside uaccess.h routines: [name:aee&]disable aee kernel api [name:mrdump&]Kernel Offset: 0x1326000000 from 0xffffff8008000000 [name:mrdump&]Non-crashing CPUs did not react to IPI CPU: 7 PID: 552 Comm: HwBinder:426_1 Tainted: G W O 4.9.117+ #2 Hardware name: MT6765 (DT) task: ffffffc62d340000 task.stack: ffffffc62d2b4000 PC is at shmem_evict_inode+0x150/0x19c LR is at evict+0xa4/0x1f4 [] el1_da+0x24/0x40 [] evict+0xa4/0x1f4 [] iput+0x338/0x384 [] fsnotify_detach_mark+0xac/0xe0 [] fsnotify_detach_group_marks+0x78/0xdc [] fsnotify_destroy_group+0x34/0x98 [] inotify_release+0x28/0x5c [] __fput+0xcc/0x1c8 [] ____fput+0xc/0x14 [] task_work_run+0x88/0x11c [] do_notify_resume+0x5c/0x165c [] work_pending+0x8/0x14 If we put a BUG() after after "VFS: Busy inodes after unmount of tmpfs. Self-destruct in 5 seconds. Have a nice day...", we can get another backtrace: [] el1_dbg+0x18/0xb8 [] kill_litter_super+0x28/0x74 [] deactivate_locked_super+0x58/0x110 [] deactivate_super+0x6c/0x78 [] cleanup_mnt+0xb4/0x130 [] __cleanup_mnt+0x10/0x18 [] task_work_run+0x88/0x11c [] do_notify_resume+0x5c/0x1664 [] work_pending+0x8/0x14 Signed-off-by: Miles Chen --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 4469426..a50a2c8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -257,7 +257,7 @@ static int shmem_reserve_inode(struct super_block *sb) static void shmem_free_inode(struct super_block *sb) { struct shmem_sb_info *sbinfo = SHMEM_SB(sb); - if (sbinfo->max_inodes) { + if (sbinfo && sbinfo->max_inodes) { spin_lock(&sbinfo->stat_lock); sbinfo->free_inodes++; spin_unlock(&sbinfo->stat_lock);