Received: by 10.192.165.148 with SMTP id m20csp801691imm; Fri, 27 Apr 2018 07:45:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr/HUlqYBzGx/TtVp4ZgR5g2YtTN2PSc9EDkhL5OTmItgve7H2xF3ZWzRVaXAY9mK3IcY1d X-Received: by 2002:a63:7c14:: with SMTP id x20-v6mr2399072pgc.161.1524840306004; Fri, 27 Apr 2018 07:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524840305; cv=none; d=google.com; s=arc-20160816; b=T0qpldCIU7y2TMviGmsasgZECOtniwBryMXcCvQtHv8lPewpFb7YpF7Un087uymUsm btoNsU5FrAtXTtpAbgn1LT4h74jFi/j/SOHfaN8HF9nw7QLUzaODbvef8OMPjVOO9ctT kF0HNc0IyPvy6/nMJTofbjGf4MfbPP/BFPZECfMpklmCAGOQA+yj+ywooieGEtRxpXGq +pMwYtAYnW3B8KtOmYZpjEYnR+1LZ6Na1xJRHUDMIQww9NIHuUlH5acm/nndZMH9s1n7 /tho4wB1WdGfS6UtOUHii+vEQqSvxaXQOMXdZ4cNHCnqgBiETWxR8HYFel8wXvTZP1fD AwXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=UIJuHGNm44JxpEcQq+gWytwxcuwFpiSbCPUm4s9c4lM=; b=lk9P4rvtYwKQ6c/Ca7ixFxCpdlC/QstmepNn/wt08g1fy/GY8gq/rJGqIxHNCTKE64 bXTukmzj1BqYtBU6QcUimUbeKiBu2Sij9KgsrlFKuXv2KekYy85a+UQWnXa8qjVGOWxP yrTdW0JmrUOdzHrAmV7SRPZmLjOIygiSKVY60ebxwytk+vrhpUnVYANfJBeMPCLHN2L/ 6kDcSmbg1/+pKe2OUtCn9bdT6Nfmb+hZ44FAnT876Rg+SajbQ6z382SU2kMmlKXdtTr5 InetuwCwCtr28mlMWp96J7tfg1EF0LosJ9gdALb9nDBANJKKVhPoxa4EymqciIfr5saY 73oQ== 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 v2-v6si1385587plo.138.2018.04.27.07.44.51; Fri, 27 Apr 2018 07:45:05 -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 S934545AbeD0OIn (ORCPT + 99 others); Fri, 27 Apr 2018 10:08:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:54198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934455AbeD0OIj (ORCPT ); Fri, 27 Apr 2018 10:08:39 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C9E5621892; Fri, 27 Apr 2018 14:08:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9E5621892 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Kolchmeyer , Jan Kara Subject: [PATCH 4.14 67/80] fsnotify: Fix fsnotify_mark_connector race Date: Fri, 27 Apr 2018 15:59:00 +0200 Message-Id: <20180427135736.363418213@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135732.928644313@linuxfoundation.org> References: <20180427135732.928644313@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Robert Kolchmeyer commit d90a10e2444ba5a351fa695917258ff4c5709fa5 upstream. fsnotify() acquires a reference to a fsnotify_mark_connector through the SRCU-protected pointer to_tell->i_fsnotify_marks. However, it appears that no precautions are taken in fsnotify_put_mark() to ensure that fsnotify() drops its reference to this fsnotify_mark_connector before assigning a value to its 'destroy_next' field. This can result in fsnotify_put_mark() assigning a value to a connector's 'destroy_next' field right before fsnotify() tries to traverse the linked list referenced by the connector's 'list' field. Since these two fields are members of the same union, this behavior results in a kernel panic. This issue is resolved by moving the connector's 'destroy_next' field into the object pointer union. This should work since the object pointer access is protected by both a spinlock and the value of the 'flags' field, and the 'flags' field is cleared while holding the spinlock in fsnotify_put_mark() before 'destroy_next' is updated. It shouldn't be possible for another thread to accidentally read from the object pointer after the 'destroy_next' field is updated. The offending behavior here is extremely unlikely; since fsnotify_put_mark() removes references to a connector (specifically, it ensures that the connector is unreachable from the inode it was formerly attached to) before updating its 'destroy_next' field, a sizeable chunk of code in fsnotify_put_mark() has to execute in the short window between when fsnotify() acquires the connector reference and saves the value of its 'list' field. On the HEAD kernel, I've only been able to reproduce this by inserting a udelay(1) in fsnotify(). However, I've been able to reproduce this issue without inserting a udelay(1) anywhere on older unmodified release kernels, so I believe it's worth fixing at HEAD. References: https://bugzilla.kernel.org/show_bug.cgi?id=199437 Fixes: 08991e83b7286635167bab40927665a90fb00d81 CC: stable@vger.kernel.org Signed-off-by: Robert Kolchmeyer Signed-off-by: Jan Kara Signed-off-by: Greg Kroah-Hartman --- include/linux/fsnotify_backend.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -217,12 +217,10 @@ struct fsnotify_mark_connector { union { /* Object pointer [lock] */ struct inode *inode; struct vfsmount *mnt; - }; - union { - struct hlist_head list; /* Used listing heads to free after srcu period expires */ struct fsnotify_mark_connector *destroy_next; }; + struct hlist_head list; }; /*