From patchwork Tue Oct 31 09:33:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10033785 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 BA52D602B9 for ; Tue, 31 Oct 2017 09:34:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7B4328997 for ; Tue, 31 Oct 2017 09:34:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC91628994; Tue, 31 Oct 2017 09:34:52 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 674D028990 for ; Tue, 31 Oct 2017 09:34:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752803AbdJaJes (ORCPT ); Tue, 31 Oct 2017 05:34:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:34018 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752411AbdJaJer (ORCPT ); Tue, 31 Oct 2017 05:34:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1F92DABED; Tue, 31 Oct 2017 09:34:46 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 800171E0F55; Tue, 31 Oct 2017 10:33:45 +0100 (CET) From: Jan Kara To: Cc: amir73il@gmail.com, Jan Kara Subject: [PATCH 2/2] fsnotify: Protect bail out path of fsnotify_add_mark_locked() properly Date: Tue, 31 Oct 2017 10:33:42 +0100 Message-Id: <20171031093342.25216-3-jack@suse.cz> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20171031093342.25216-1-jack@suse.cz> References: <20171031093342.25216-1-jack@suse.cz> 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 When fsnotify_add_mark_locked() fails it cleans up the mark it was adding. Since the mark is already visible in group's list, we should protect update of mark->flags with mark->lock. I'm not aware of any real issues this could cause (since we also hold group->mark_mutex) but better be safe and obey locking rules properly. Signed-off-by: Jan Kara Reviewed-by: Amir Goldstein --- fs/notify/mark.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 9991f8826734..47a827975b58 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -599,9 +599,11 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode, return ret; err: + spin_lock(&mark->lock); mark->flags &= ~(FSNOTIFY_MARK_FLAG_ALIVE | FSNOTIFY_MARK_FLAG_ATTACHED); list_del_init(&mark->g_list); + spin_unlock(&mark->lock); atomic_dec(&group->num_marks); fsnotify_put_mark(mark);