Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sunrpc: don't mark uninitialised items as VALID.

A recent commit added a call to cache_fresh_locked()
when an expired item was found.
The call sets the CACHE_VALID flag, so it is important
that the item actually is valid.
There are two ways it could be valid:
1/ If ->update has been called to fill in relevant content
2/ if CACHE_NEGATIVE is set, to say that content doesn't exist.

An expired item that is waiting for an update will be neither.
Setting CACHE_VALID will mean that a subsequent call to cache_put()
will be likely to dereference uninitialised pointers.

So we must make sure the item is valid, and we already have code to do
that in try_to_negate_entry(). This takes the hash lock and so cannot
be used directly, so take out the two lines that we need and use them.

Now cache_fresh_locked() is certain to be called only on
a valid item.

Cc: stable@kernel.org # 2.6.35
Fixes: 4ecd55ea0742 ("sunrpc: fix cache_head leak due to queued request")
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>

authored by

NeilBrown and committed by
J. Bruce Fields
d58431ea 79a3aaa7

+3
+3
net/sunrpc/cache.c
··· 54 54 h->last_refresh = now; 55 55 } 56 56 57 + static inline int cache_is_valid(struct cache_head *h); 57 58 static void cache_fresh_locked(struct cache_head *head, time_t expiry, 58 59 struct cache_detail *detail); 59 60 static void cache_fresh_unlocked(struct cache_head *head, ··· 106 105 if (cache_is_expired(detail, tmp)) { 107 106 hlist_del_init_rcu(&tmp->cache_list); 108 107 detail->entries --; 108 + if (cache_is_valid(tmp) == -EAGAIN) 109 + set_bit(CACHE_NEGATIVE, &tmp->flags); 109 110 cache_fresh_locked(tmp, 0, detail); 110 111 freeme = tmp; 111 112 break;