From patchwork Thu Oct 19 13:58:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10017087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8196E600CC for ; Thu, 19 Oct 2017 13:58:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B79728D59 for ; Thu, 19 Oct 2017 13:58:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7048028D61; Thu, 19 Oct 2017 13:58:51 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 248CB28D59 for ; Thu, 19 Oct 2017 13:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754897AbdJSN6q (ORCPT ); Thu, 19 Oct 2017 09:58:46 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:50470 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754569AbdJSN6n (ORCPT ); Thu, 19 Oct 2017 09:58:43 -0400 Received: by mail-wm0-f67.google.com with SMTP id u138so16223550wmu.5 for ; Thu, 19 Oct 2017 06:58:43 -0700 (PDT) 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:in-reply-to :references; bh=vNRvonjsGz+Cdl0RQlk+oIgRSNMK+sxh31xOy10vMrI=; b=DbLVAF9peB4BI5ofgRldxTSl3BUyhIUdBmbABxInmXZeCdHnP4krhSB48G6Uqhr+U8 /jHXXX6T7JvLMn3E+TyZqu6eWmseXuXtDQ7zSPgE9uDJ4sC6jl9SuuBtjSWPk2V63es3 9HEgtCleYJKB7jaGOQ2aGmW91+37MiP/33tVzmHor+x2qyrHnv0qpZ61BALg1C/hKFLB zckB4PDLk84+QS35BhKI+ZAp5GHnPFrw9qQ88f36l8gfefckrFcOloeM6BAVDPTCjn4d cl7FR89lICI+ZHfoOZv/URF5ef+8UUtNYyO7zYKaihIrkQL7/hbbjMSIB8v/b3QY7Q2J jKsg== X-Gm-Message-State: AMCzsaXs+f4AzL4+Ci/1ntSGQv/DYWSF0w1xr6QADu9x1dB1MwFBm4IA /01gzZljQZLocrG+METmsexRiPIpyco= X-Google-Smtp-Source: ABhQp+Qvs27EbjMzmrxDlB18RS8HEDeRbymVt7QfrvK9vVEgd32IbTDIIAQpslcnkxbRV4t0ook/8w== X-Received: by 10.28.111.19 with SMTP id k19mr1643067wmc.84.1508421522394; Thu, 19 Oct 2017 06:58:42 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id h185sm3613279wma.19.2017.10.19.06.58.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Oct 2017 06:58:41 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Jan Kara , Amir Goldstein , Xiong Zhou , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] fsnotify: skip unattached marks Date: Thu, 19 Oct 2017 15:58:35 +0200 Message-Id: <1508421517-22678-3-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1508421517-22678-1-git-send-email-mszeredi@redhat.com> References: <1508421517-22678-1-git-send-email-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After having gone through a ref-unref for the mark, dereferencing the group (e.g. in fsnotify_compare_groups()) is wrong since the group may be completely gone by that time. So before continuing to traverse the mark list, check if the mark is still attached. This is done in the generic case, not just when we go through fsnotify_prepare_user_wait()/fsnotify_finish_user_wait(), otherwise it would introduce unnecessary complexity. And it shouldn't hurt to skip unattached marks anyway ("flags" is very likely in same cacheline as neighbouring "ignored_mask", which is pulled in anyway). Signed-off-by: Miklos Szeredi Fixes: 9385a84d7e1f ("fsnotify: Pass fsnotify_iter_info into handle_event handler") Cc: # v4.12 --- fs/notify/fsnotify.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 48ec61f4c4d5..0ab6a7179e4d 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -328,12 +328,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, inode_mark = hlist_entry(srcu_dereference(inode_node, &fsnotify_mark_srcu), struct fsnotify_mark, obj_list); inode_group = inode_mark->group; + if (!(inode_mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) + goto skip_inode; } if (vfsmount_node) { vfsmount_mark = hlist_entry(srcu_dereference(vfsmount_node, &fsnotify_mark_srcu), struct fsnotify_mark, obj_list); vfsmount_group = vfsmount_mark->group; + if (!(vfsmount_mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) + goto skip_vfsmount; } iter_info.inode_mark = inode_mark; @@ -357,10 +361,11 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) goto out; - +skip_inode: if (inode_group) inode_node = srcu_dereference(inode_node->next, &fsnotify_mark_srcu); +skip_vfsmount: if (vfsmount_group) vfsmount_node = srcu_dereference(vfsmount_node->next, &fsnotify_mark_srcu);