From: ebiederm@xmission.com (Eric W. Biederman) Subject: Re: [PATCH] mnt: Fix a memory stomp in umount Date: Fri, 02 Jan 2015 15:06:06 -0600 Message-ID: <87lhlkvqo1.fsf@x220.int.ebiederm.org> References: <87d27gkia8.fsf@x220.int.ebiederm.org> <87h9wsiwwl.fsf@x220.int.ebiederm.org> <20141218210553.GQ22149@ZenIV.linux.org.uk> <87d27ghd1i.fsf@x220.int.ebiederm.org> <20141219000215.GR22149@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain Cc: Linus Torvalds , linux-fsdevel To: Al Viro Return-path: Received: from out03.mta.xmission.com ([166.70.13.233]:45115 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750777AbbABVIp (ORCPT ); Fri, 2 Jan 2015 16:08:45 -0500 In-Reply-To: <20141219000215.GR22149@ZenIV.linux.org.uk> (Al Viro's message of "Fri, 19 Dec 2014 00:02:15 +0000") Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Al Viro writes: > On Thu, Dec 18, 2014 at 03:18:49PM -0600, Eric W. Biederman wrote: > >> We might have wanted to because before your change to an hlist that is >> what the code did. >> >> Having read through the code of propagate_next it does look like it >> iterates through the entire propagation hierarchy so there shouldn't be >> a need to visit mounts that we have placed on the propagation list. >> >> Any thoughts on using mnt_list instead of mnt_hash to allow the use of >> list_splice and list_move? > > Frankly, I don't see much benefit in that. What's wrong with actually > adding > __hlist_splice(struct hlist_node *head, > struct hlist_node *tail, > struct hlist_node **where) > { > next = *where; > *where = head; > head->pprev = where; > if (next) { > tail->next = next; > next->pprev = tail; > } > } > > and use it as > __hlist_splice(tmp_list.first, &last->mnt_hash, &unmounted.first); > (and I'd start with if (unlikely(!mnt)) return; /* idiot caller */) I have a couple of reasons for not wanting to go that way. - It requires keeping track of the tail of the list which is half of the error prone complexity. - I have a fix for a bad interaction between MNT_LOCKED and MNT_DETACH where I need to leave mounts on the mount hash, until the final mntput. For that I need not to reuse the the mnt_hash lists. Patches to follow shortly. Of course after having gone through this code a time or two and tested things I am very annoyed by the fact that "hlist_add_before_rcu()" and "list_move_tail" perform the same operation. That is down right confusing. > Another primitive would be something like > hlist_transplant(struct hlist_head **from, struct hlist_head **to) > { > *to = *from; > if (!hlist_empty(*to)) { > to->first->pprev = to; > INIT_HLIST_HEAD(from); > } > } > > with namespace_unlock() starting with > hlist_transplant(&head, &unmounted); > if (likely(hlist_empty(&head))) { > up_write(&namespace_sem); > return; > } > /* undo decrements we'd done in umount_tree() */ > ... > > Linus, would that work for you, or would you prefer something more fancy? Eric