lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 29 Jan 2016 10:35:57 -0800
From:	Davidlohr Bueso <dave@...olabs.net>
To:	Hugh Dickins <hughd@...gle.com>
Cc:	Davidlohr Bueso <dbueso@...e.de>,
	Mel Gorman <mgorman@...hsingularity.net>,
	Peter Zijlstra <peterz@...radead.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...nel.org>,
	Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
	Chris Mason <clm@...com>, Darren Hart <dvhart@...ux.intel.com>,
	linux-kernel@...r.kernel.org, Mel Gorman <mgorman@...e.de>
Subject: Re: [PATCH v4] futex: Remove requirement for lock_page in
 get_futex_key

On Wed, 27 Jan 2016, Hugh Dickins wrote:

>> +		 *
>> +		 * The RCU read lock is taken as the inode is finally freed
>> +		 * under RCU. If the mapping still matches expectations then the
>> +		 * mapping->host can be safely accessed as being a valid inode.
>> +		 */
>> +		rcu_read_lock();
>> +		if (READ_ONCE(page->mapping) != mapping ||
>> +		    !mapping->host) {
>
>If you're being as paranoid as all the WARN_ON_ONCEs hereabouts imply,
>then it would be better to do the inode = READ_ONCE(mapping->host)
>before checking !inode rather than !mapping->host.

Ok, it also reads a bit nicer than the above, which was simply avoiding
a load in the again case.

                rcu_read_lock();
                inode = READ_ONCE(mapping->host);

                if (!inode || READ_ONCE(page->mapping) != mapping)
                        rcu_read_unlock();
                        put_page(page);

                        goto again;
                }

[...]

>> +
>> +		/* Should be impossible but lets be paranoid for now */
>> +		if (WARN_ON_ONCE(inode->i_mapping != mapping)) {
>> +			err = -EFAULT;
>> +			iput(inode);
>> +			rcu_read_unlock();
>
>I think this is probably a WARN_ON_ONCE too many (but I'm error-prone on
>inode -> i_mapping -> host relationships, so ignore me); but if it's kept
>then I think you ought to do the iput(inode) after the rcu_read_unlock() -
>iput() can get into lots more work than you expect.

I'd rather keep some verbosity if something screws up here, albeit very rare, yes.
You make a good point about doing the inode cleanup while holding rcu, and moving
it down should be safe here even if the inode disappears after that iput (ie no
dereferencing). Secondly, we still hold reference to the inode by the time we drop
the rcu read lock, so thats safe too.

>
>Otherwise it appeared to be good to me (but years since I've been near here).

Thanks for taking a look at this. I'll send a v5 with your suggestions.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ