From: Namjae Jeon Subject: RE: [PATCH] fsnotify: fix a crash due to invalid virtual address Date: Tue, 23 Jun 2015 16:33:12 +0900 Message-ID: <009501d0ad86$dc1968a0$944c39e0$@samsung.com> References: <1434970396-19644-1-git-send-email-a.sangwan@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: 'Ashish Sangwan' , linux-fsdevel@vger.kernel.org, 'Jan Kara' , 'Andrew Morton' , 'Eric Paris' , 'Amit Sahrawat' , 'Pankaj Mishra' To: 'Lino Sanfilippo' Return-path: Received: from mailout3.samsung.com ([203.254.224.33]:46920 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753241AbbFWHdP (ORCPT ); Tue, 23 Jun 2015 03:33:15 -0400 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NQD0072TZNCKF00@mailout3.samsung.com> for linux-fsdevel@vger.kernel.org; Tue, 23 Jun 2015 16:33:12 +0900 (KST) In-reply-to: <1434970396-19644-1-git-send-email-a.sangwan@samsung.com> Content-language: ko Sender: linux-fsdevel-owner@vger.kernel.org List-ID: + Lino Sanfilippo > > For deleting the fsnotify_mark related with an inode, there are 2 paths in the > kernel. When the inotify fd is closed, all the marks belonging to a group are > removed one by one in fsnotify_clear_marks_by_group_flags. Other path is when > the inode is removed from user space by unlink, fsnotify_destroy_mark is > called to delete a single mark. > There is a race between these 2 paths which is caused due to the temporary > release of the mark_mutex inside fsnotify_destroy_mark_locked. > The race happen when the inotify app monitoring the file(s) exits, triggering > fsnotify_clear_marks_by_group_flags to delete the marks. > This function use lmark pointer to move to the next node after a safe removal > of the node. In parallel, if there is rm call for a file and such that the > lmark is pointing to the mark which is removed by this rm call, lmark ends up > pointing to a freed memory. Now, when we try to move to the next node using > lmark, it triggers an invalid virtual address crash. > Although fsnotify_clear_marks_by_group_flags and fsnotify_destroy_mark are > synchronized by mark_mutex, but both of these functions call > fsnotify_destroy_mark_locked which release the mark_mutex and acquire it again > creating a subtle race window. There seems to be no reason for releasing > mark_mutex, so this patch remove the mutex_unlock call. > > Signed-off-by: Ashish Sangwan > Reviewed-by: Amit Sahrawat > --- > fs/notify/mark.c | 4 ---- > 1 files changed, 0 insertions(+), 4 deletions(-) > > diff --git a/fs/notify/mark.c b/fs/notify/mark.c > index 92e48c7..4ee419f 100755 > --- a/fs/notify/mark.c > +++ b/fs/notify/mark.c > @@ -157,8 +157,6 @@ void fsnotify_destroy_mark_locked(struct fsnotify_mark *mark, > > if (inode && (mark->flags & FSNOTIFY_MARK_FLAG_OBJECT_PINNED)) > iput(inode); > - /* release lock temporarily */ > - mutex_unlock(&group->mark_mutex); > > spin_lock(&destroy_lock); > list_add(&mark->g_list, &destroy_list); > @@ -191,8 +189,6 @@ void fsnotify_destroy_mark_locked(struct fsnotify_mark *mark, > */ > > atomic_dec(&group->num_marks); > - > - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); > } > > void fsnotify_destroy_mark(struct fsnotify_mark *mark, > -- > 1.7.7 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in