Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp624646imm; Fri, 22 Jun 2018 02:26:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK7V/aN6ecC+nqRH9+R7IvutofOXJg4gCxbRYxExNN0KAYKmEjDxkekLtGZkN8Ni8yx/spC X-Received: by 2002:a65:4e09:: with SMTP id r9-v6mr685923pgt.369.1529659575567; Fri, 22 Jun 2018 02:26:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529659575; cv=none; d=google.com; s=arc-20160816; b=maQY782o9igkp3mgq+fE4OVGHSvIDJj6Bi0f55Nn1qMKOBqjv3GMD0WIwNbnv5U5LI 41iRQPiFI/KLHLrIcbQjhye3l+RbCIgzq8V2f9nCWUpbJK9DBt02gFGfB4XpCoPOypBZ eAUax88CcCc+65RfM3Ke4hO8ue9uJREMPbAr8GAgw4op9o+KhWsJVUBMXB8ci08LiCuu wVAKcVeZzI2k/PmNygC5DQ594ZRQK2D5sg+psfk6Nk7tV6L175Q8RQ5IXpnqRJObYigy 1lbzLqaX2EW7IIxHUCxtqfr7yvFE9SvLHQb6baqd5YT6ZPfFBpSIRofuji+xBsCpKXXK ghcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=JUNpe3EsWOqR1DzNr8xkgXqQKwt6mSciFDUnAumYgbQ=; b=0BALA6d61pJ3kegQBaZ1HqNVZ0c8kMPJo8H2joBKSH5sHdK39Xp7q2R0NzMb7hTbBN dmHr2jGB/cTTdm3OpzYA4uf+vi+0RTfdGK1e5/jpGjBW3SJMQwoHED5kqFo9+P/Btuna gvX+VAhkbG4+0VuWNTRe1O15KRxLvdwYLUaJz/O6rvy/6PdtEr/MfVnD1Ul5FGBnfqS8 b0UZG0TNw/cZ4HPlKKdgeQAl4XpGCN/GR+ul15ljMRBerK3T87GAAnAfn/R3tvzhohYU NN7hbHUzBICra1mlBeY/GcRmVCZA93yGmrmmgNeQoEVLlDbBsfULjM3T5m3yS/HHoWpm ytVA== 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 n4-v6si6682442plp.128.2018.06.22.02.25.31; Fri, 22 Jun 2018 02:26:15 -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 S1752429AbeFVJXp (ORCPT + 99 others); Fri, 22 Jun 2018 05:23:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:56159 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751214AbeFVJXm (ORCPT ); Fri, 22 Jun 2018 05:23:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 657E7ACA5; Fri, 22 Jun 2018 09:23:41 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id D53A01E3529; Fri, 22 Jun 2018 11:23:40 +0200 (CEST) Date: Fri, 22 Jun 2018 11:23:40 +0200 From: Jan Kara To: Matthew Wilcox Cc: Jia-Ju Bai , paul@paul-moore.com, eparis@redhat.com, jack@suse.cz, amir73il@gmail.com, linux-audit@redhat.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] kernel: audit_tree: Fix a sleep-in-atomic-context bug Message-ID: <20180622092340.dzl2ea7tdkjdkdhg@quack2.suse.cz> References: <20180621033245.10754-1-baijiaju1990@gmail.com> <20180621042912.GA4967@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180621042912.GA4967@bombadil.infradead.org> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 20-06-18 21:29:12, Matthew Wilcox wrote: > On Thu, Jun 21, 2018 at 11:32:45AM +0800, Jia-Ju Bai wrote: > > The kernel may sleep with holding a spinlock. > > The function call paths (from bottom to top) in Linux-4.16.7 are: > > > > [FUNC] kmem_cache_alloc(GFP_KERNEL) > > fs/notify/mark.c, 439: > > kmem_cache_alloc in fsnotify_attach_connector_to_object > > fs/notify/mark.c, 520: > > fsnotify_attach_connector_to_object in fsnotify_add_mark_list > > fs/notify/mark.c, 590: > > fsnotify_add_mark_list in fsnotify_add_mark_locked > > kernel/audit_tree.c, 437: > > fsnotify_add_mark_locked in tag_chunk > > kernel/audit_tree.c, 423: > > spin_lock in tag_chunk > > There are several locks here; your report would be improved by saying > which one is the problem. I'm assuming it's old_entry->lock. > > spin_lock(&old_entry->lock); > ... > if (fsnotify_add_inode_mark_locked(chunk_entry, > old_entry->connector->inode, 1)) { > ... > return fsnotify_add_mark_locked(mark, inode, NULL, allow_dups); > ... > ret = fsnotify_add_mark_list(mark, inode, mnt, allow_dups); > ... > if (inode) > connp = &inode->i_fsnotify_marks; > conn = fsnotify_grab_connector(connp); > if (!conn) { > err = fsnotify_attach_connector_to_object(connp, inode, mnt); > > It seems to me that this is safe because old_entry is looked up from > fsnotify_find_mark, and it can't be removed while its lock is held. > Therefore there's always a 'conn' returned from fsnotify_grab_connector(), > and so this path will never be taken. > > But this code path is confusing to me, and I could be wrong. Jan, please > confirm my analysis is correct? Yes, you are correct. The presence of another mark in the list (and the fact we pin it there using refcount & mark_mutex) guarantees we won't need to allocate the connector. I agree the audit code's use of fsnotify would deserve some cleanup. Honza -- Jan Kara SUSE Labs, CR