Received: by 10.192.165.148 with SMTP id m20csp779400imm; Fri, 27 Apr 2018 07:24:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrfbPHP0ddwl49JH4dgyCn3ROReUhcoZCQlHgZ4aZ49BrrMhrK2rC9tXFM+Mqzf+m2UpwIc X-Received: by 2002:a17:902:683:: with SMTP id 3-v6mr2518264plh.206.1524839056345; Fri, 27 Apr 2018 07:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524839056; cv=none; d=google.com; s=arc-20160816; b=OrulP5wtosWjkYqgt7yjrKfOojOVuNbyEE7YqrnxRo1THtWAFec4u1tSPE5cTIvqir xaq9JdQx+3GMi4t/vQtxegMleC8VbijL2+JyfzvLqTjQqnXdlHUBtZnF0s0n0qMfuz3c 1XCJxJYwQE3DtjAtnW+QarvgG6r1aqiWStRRJ8YBI5OZD2netfhkZRbTaOiF1d3LYjYb iF8JxHYZKKQksbBd1NEbDwiXhvc4sF1ANqlqecBF5qwAWcKUuL7ADnu/QHQbUJr5xBl7 FroZQ1pxbigK6GFQDheouIHXYK38m7ZnHFk1+D57eh/orOc3wFzaz7EvaNEblQ+x1S5n L4Aw== 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=cYPHppv2z+eAv9HOGZLXHF8mamvH7snDbcKjvWdRvlw=; b=OF1MzBUhxbVKVm7rTgZro8ALYcqHHIkNlfgR7q0odVjhfHHmkLa141rzssGXAiPGmT EGzHzIby25VmScjya4amM4jYztJoirBQ1SHctQK+PCSEqPvGSTfFPgeuzpV9WBjVFIw6 K6HyaIu3cbK1beaoSVNwAuRPnpfBYMBt+2uA01Eo9InmKHoBSNWKu0FVNzCfz3UJtHv6 atf4kZ54UP1cjuIbsSjoLola/StKqFAqMC1I+jbrDTqJjo2CZGT276PHkURPTqWiNeSl RQNLvxhq1Q2hgC+jGqUvsgjy9V7b/NoqExFTAPWq8qbZurhkqwlg1Um0R35kKF02HsCb +WRA== 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 f3-v6si1330515pld.513.2018.04.27.07.24.02; Fri, 27 Apr 2018 07:24:16 -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 S935179AbeD0OMZ (ORCPT + 99 others); Fri, 27 Apr 2018 10:12:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:56798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935130AbeD0OMM (ORCPT ); Fri, 27 Apr 2018 10:12:12 -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 93864218A1; Fri, 27 Apr 2018 14:12:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93864218A1 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.16 64/81] fsnotify: Fix fsnotify_mark_connector race Date: Fri, 27 Apr 2018 15:59:06 +0200 Message-Id: <20180427135747.053318680@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135743.216853156@linuxfoundation.org> References: <20180427135743.216853156@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.16-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; }; /*