Skip to contentSkip to conversation

posix_acl: de-union a_refcount and a_rcu

PATCH Applied Andreas Gruenbacher 4 participants 4 messages Jul 11, 2016 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 posix_acl: de-union a_refcount and a_rcu

From: Jeff Layton <[email protected]>

Currently the two are unioned together, but I don't think that's safe.

It looks like get_cached_acl could race with the last put in posix_acl_release. get_cached_acl calls atomic_inc_not_zero on a_refcount, but that field could have already been clobbered by call_rcu, and may no longer be zero. Fix this by de-unioning the two fields.

Fixes b8a7a3a66747 (v4.7-rc1, posix_acl: Inode acl caching fixes)
---
 include/linux/posix_acl.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
include/linux/posix_acl.h +2 -4
index 5b5a80c..c818772 100644
@@ -43,10 +43,8 @@ struct posix_acl_entry {
 };
 
 struct posix_acl {
-	union {
-		atomic_t		a_refcount;
-		struct rcu_head		a_rcu;
-	};
+	atomic_t		a_refcount;
+	struct rcu_head		a_rcu;
 	unsigned int		a_count;
 	struct posix_acl_entry	a_entries[0];
 };
Signature · 1 line
2.5.5
#1 lore raw
Quoted 3 lines · Andreas Gruenbacher

From: Jeff Layton <[email protected]>

Currently the two are unioned together, but I don't think that's safe.

Ack. That does look fishy. Almost anything else can probably be unioned together with the rcu list, but *not* the refcount that we might want to look at during the rcu grace period.

Al, this is your code (from long long ago). Want to take it through the vfs tree, or should I just apply direectly? I'd like to have your ack regardless, but the fix looks ObviouslyCorrect(tm) to me.

Linus

#2 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 4 lines · Andreas Gruenbacher

From: Jeff Layton <[email protected]>

Currently the two are unioned together, but I don't think that's safe.

Ack. That does look fishy. Almost anything else can probably be unioned together with the rcu list, but *not* the refcount that we might want to look at during the rcu grace period.

I looked at unioning the rcu_head it with something else, but there's nothing else that doesn't get peeked at in an rcu-critical section. So I think this is the only real fix, unfortunately.

Quoted 4 lines

Al, this is your code (from long long ago). Want to take it through the vfs tree, or should I just apply direectly? I'd like to have your ack regardless, but the fix looks ObviouslyCorrect(tm) to me.

I think this is a v4.7 regression. We've freed these things via RCU for a long time, but monkeying with the refcount under the rcu_read_lock is new with the patch in the "Fixes:" line, AFAICT.

Signature · 1 line
Jeff Layton <[email protected]>
maintainer Applied
#3 lore raw
In reply to Linus Torvalds
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Andreas Gruenbacher

From: Jeff Layton <[email protected]>

Currently the two are unioned together, but I don't think that's safe.

Quoted 7 lines

Ack. That does look fishy. Almost anything else can probably be unioned together with the rcu list, but *not* the refcount that we might want to look at during the rcu grace period.

Al, this is your code (from long long ago). Want to take it through the vfs tree, or should I just apply direectly? I'd like to have your ack regardless, but the fix looks ObviouslyCorrect(tm) to me.

Applied; the mess had been caused by get_cached_acl() switch from ->i_lock to rcu_read_lock. The code is mine, but relevant part is fairly recent.

I'll send a pull request tonight, with that thing included.