From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C73FEC43219 for ; Tue, 30 Apr 2019 11:55:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99C6A2075E for ; Tue, 30 Apr 2019 11:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556625346; bh=ZBbxzEzM68irpAlpYV2xErPYncDbMHz9b36z2Ynmjd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MjAAD5N7dFkucU53TW7JE9SCjxM01KgNtlmzrL+/vcUSBldMqEvirHjF1s39cUJ16 mwl2/FB1z+LT5h7n+gIZT+BB67w+EbbWQ5Axo3Ucv5odOT6qVKkhdmCf0QDb/KU6hF 683Bl2181TIx+pl9JxOcZPNNy7mN7SR9WOnq1LFk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730966AbfD3LtP (ORCPT ); Tue, 30 Apr 2019 07:49:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:35606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730934AbfD3LtK (ORCPT ); Tue, 30 Apr 2019 07:49:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4B2362177B; Tue, 30 Apr 2019 11:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624949; bh=ZBbxzEzM68irpAlpYV2xErPYncDbMHz9b36z2Ynmjd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iQ0liYcHbalUI0cit/ips0burQQy3Qik9lfR3tXWugFdZ4TiaNOlrAVhm5P30PrFo lwvgqhjwOlX2Pj1Y1gApktSMHDyW4zXhpAq9io20G1z3sVnpgyFdQ3edBuvjNoRiRT hYsT3uNs/MPt5hMIAxTZNnejNk7zY1UOjtcq7A9A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , "J. Bruce Fields" , stable@kernel.org Subject: [PATCH 5.0 33/89] sunrpc: dont mark uninitialised items as VALID. Date: Tue, 30 Apr 2019 13:38:24 +0200 Message-Id: <20190430113611.449275841@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown commit d58431eacb226222430940134d97bfd72f292fcd upstream. 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 Signed-off-by: J. Bruce Fields Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/cache.c | 3 +++ 1 file changed, 3 insertions(+) --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -54,6 +54,7 @@ static void cache_init(struct cache_head h->last_refresh = now; } +static inline int cache_is_valid(struct cache_head *h); static void cache_fresh_locked(struct cache_head *head, time_t expiry, struct cache_detail *detail); static void cache_fresh_unlocked(struct cache_head *head, @@ -105,6 +106,8 @@ static struct cache_head *sunrpc_cache_a if (cache_is_expired(detail, tmp)) { hlist_del_init_rcu(&tmp->cache_list); detail->entries --; + if (cache_is_valid(tmp) == -EAGAIN) + set_bit(CACHE_NEGATIVE, &tmp->flags); cache_fresh_locked(tmp, 0, detail); freeme = tmp; break;