Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4828597yba; Tue, 30 Apr 2019 05:10:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZZPkGNnZ0dh0BFni0vGVBZ3tkDHJSVyXXfmKA+oXT0N0Mawo44QRD/KruivvN8CzEak7S X-Received: by 2002:a62:a503:: with SMTP id v3mr38040749pfm.32.1556626204302; Tue, 30 Apr 2019 05:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556626204; cv=none; d=google.com; s=arc-20160816; b=EXAMuBcYTbhKwzHGc0YWqODcZ861muwGl7Ub3Gh1Tsc4tup0YIHs1oVAG4Vq/ujcF0 BM6R3Rt+yViHGUvM9H0IKZNG6t+IqoLXZig5xE+3OvhKCma6CNmtQcE1p0ad+MadZyMu sDVSm/juRI768QM67JF6+lBrQJq8vYqDzu+7IADDTkuVctx5QjmKIgARkFmD9BFBFZFy /35MxISBARqCfkG/EygnYo7w28QDTomeRTxmVbqV6A23Jlz+LQ80pai1iBd7Z2qa165b Mc2zQ4dQ4Y05tmB2+2+Dfbvgy75KehGNBEqronIhKfFgw0TvB97fOC+sieBWD3FtHTRY Dfjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3l/YGy5XUeEcd8Jt1Ja/gZ8DM6fWMSWR4nXtNRHC3yM=; b=w0PmnbeQsE+prQ7DvY6TO+TuJuRoEsJZN9aZ4bsfrg6Cr2+IRmOfO2eUhWDIJojUQV R8mOwx0vqyi2YsOpL3HrhbXdddFYGJ4HAy9gWm6HBugZg+0B9jq51MR25pNBOMFTGbM7 +9YBLFGEZoqoEZE1IcfPodNZviCIroDRfD3v4ncSplGe0BwARGjaIbtpqolufdmQsbew e34RFBaMSrJtopT8Q8LASKurEX06FhVQoOiHkDftMNdItLqVRw/SR2cpokIIfvJ3xTH4 Z5p8ufB7qFKT36MnHDPYdpCuPw8R8b6apKQWQROqQ0Cj98bY2Gc/oPmubQnsB7liApLm b58g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Klsx+bRE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c16si14734654pgm.430.2019.04.30.05.09.47; Tue, 30 Apr 2019 05:10:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Klsx+bRE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727927AbfD3Ljj (ORCPT + 99 others); Tue, 30 Apr 2019 07:39:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:44940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727654AbfD3Ljf (ORCPT ); Tue, 30 Apr 2019 07:39:35 -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 E3F0A21670; Tue, 30 Apr 2019 11:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624374; bh=xTz0TplUvCuk3TISQVkGrsJzMSmpwDhzVRj928ZBAqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Klsx+bREMJSgIycokV1yjOf19nUH4mvx793t65XUDMLALrAcuyZ5tA+nz7mlfgah1 gEUZu+bXYOiEbIT+bnlhtiBJVlZBzi3dFZvliAN+UVQzYzt6QC/pN0brRquti2jj4m RAZpAZdsHGd8xL0YAcwLeBTA26PFaIRBYuwH8Qp8= 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 4.9 11/41] sunrpc: dont mark uninitialised items as VALID. Date: Tue, 30 Apr 2019 13:38:22 +0200 Message-Id: <20190430113527.693910490@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113524.451237916@linuxfoundation.org> References: <20190430113524.451237916@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, @@ -100,6 +101,8 @@ struct cache_head *sunrpc_cache_lookup(s if (cache_is_expired(detail, tmp)) { hlist_del_init(&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;