Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1989680imu; Fri, 14 Dec 2018 04:09:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/XXwIjVb9bK/nOPZ68/TkGXqqFARgABZ/pysPF38PYf3lJGUFuHydGmFnFRIm4svqtkUi1y X-Received: by 2002:a62:4181:: with SMTP id g1mr2567508pfd.45.1544789363202; Fri, 14 Dec 2018 04:09:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789363; cv=none; d=google.com; s=arc-20160816; b=bUUXdt7D246ztFHPOsY2QD6RCUypqKDCPZy9Am4f1uhu8HUW5LOS7lfuBOCOWmt0Jq CcIQGZH09v6yWLt6d/1yTTtJtRolzK5J9k+loynNfrH+B/71AA8R1Awai0gkJwWA4hAf 36ESEpw4uBrflxBO+pengLetHfJXXaR3dKtQ3JcDuWw0wCvj+QzhqGvLknVKqEvQmnXN pWXU6ax/NR3Hqvp4btbHouIZ3Xp9nFKFMSwi+G7Mr2lMEQxtG09mBNbWDPhFzsqntThy 4AWlTPk3r73DSg9TLXJ9Q9n9/Vk5GZgbeLs7Ehw/wUqIZq+mziHX9v7HxCi7bxl8rWnZ Ha7Q== 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=Sm9PpZGkbaRMtOyMK+eQLNg2Naf9gG0rIXvoHB1qv/Y=; b=ORozFE1nI77hk9RPWzAS2aZbGPXszdj14scJLLOupcLkxstik2ifOcycXmmSy29d39 FYALC5Tmsmy4EXPKg2TBbWK+zOoDjxf24fsTF4h0ccnP3piOdg5i8+0DgdRGXGbV1LOp NILunlPkchhjrjuTvfDVfRhpjObWrAwOx0RGBwGWv7hEsyBR9Ow33tUXq2E2eYgsV6u/ VXy/2Rk8vbBVjTOBAJnPYQGybTgOGv0lePt5GxIJ8B+4mqqv+h8NoPviAQQALBKZ221q E9SBn+Lzwg0GdsPsyMu/kxaV58qwNuYks0bwINapGC254IYkrpg6pWI+sKDRAdsiD9Fr 7PnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O9HqeCAf; 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 j3si3721528plk.199.2018.12.14.04.09.05; Fri, 14 Dec 2018 04:09:23 -0800 (PST) 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=O9HqeCAf; 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 S1730847AbeLNMGD (ORCPT + 99 others); Fri, 14 Dec 2018 07:06:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:50960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730381AbeLNMGA (ORCPT ); Fri, 14 Dec 2018 07:06:00 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 A76D921479; Fri, 14 Dec 2018 12:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789159; bh=e35lxz3Ffdp3H4PhkvHbp10FhrQtZfYTEfR7nwka9fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O9HqeCAfiUUXRHURK2xMgkk9cF3ZDmUsTLpYEEaLB7OQbftt1TEuZMBeLg3cFUwRC JapRVohkoz3zyx5cnc7gWY5oY1TuL99aUsXlw5IozSXnlikIVp/KvtT19kXbWSfOk1 W+jjhS2ZZXoLFRUv3XOFyoNkl9rVn8vJfi16orkA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Al Viro , Sasha Levin Subject: [PATCH 4.19 116/142] afs: Fix validation/callback interaction Date: Fri, 14 Dec 2018 13:00:01 +0100 Message-Id: <20181214115751.678281412@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit ae3b7361dc0ee9a425bf7d77ce211f533500b39b ] When afs_validate() is called to validate a vnode (inode), there are two unhandled cases in the fastpath at the top of the function: (1) If the vnode is promised (AFS_VNODE_CB_PROMISED is set), the break counters match and the data has expired, then there's an implicit case in which the vnode needs revalidating. This has no consequences since the default "valid = false" set at the top of the function happens to do the right thing. (2) If the vnode is not promised and it hasn't been deleted (AFS_VNODE_DELETED is not set) then there's a default case we're not handling in which the vnode is invalid. If the vnode is invalid, we need to bring cb_s_break and cb_v_break up to date before we refetch the status. As a consequence, once the server loses track of the client (ie. sufficient time has passed since we last sent it an operation), it will send us a CB.InitCallBackState* operation when we next try to talk to it. This calls afs_init_callback_state() which increments afs_server::cb_s_break, but this then doesn't propagate to the afs_vnode record. The result being that every afs_validate() call thereafter sends a status fetch operation to the server. Clarify and fix this by: (A) Setting valid in all the branches rather than initialising it at the top so that the compiler catches where we've missed. (B) Restructuring the logic in the 'promised' branch so that we set valid to false if the callback is due to expire (or has expired) and so that the final case is that the vnode is still valid. (C) Adding an else-statement that ups cb_s_break and cb_v_break if the promised and deleted cases don't match. Fixes: c435ee34551e ("afs: Overhaul the callback handling") Signed-off-by: David Howells Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/afs/inode.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 479b7fdda124..071075d775a9 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -379,7 +379,7 @@ void afs_zap_data(struct afs_vnode *vnode) int afs_validate(struct afs_vnode *vnode, struct key *key) { time64_t now = ktime_get_real_seconds(); - bool valid = false; + bool valid; int ret; _enter("{v={%x:%u} fl=%lx},%x", @@ -399,15 +399,21 @@ int afs_validate(struct afs_vnode *vnode, struct key *key) vnode->cb_v_break = vnode->volume->cb_v_break; valid = false; } else if (vnode->status.type == AFS_FTYPE_DIR && - test_bit(AFS_VNODE_DIR_VALID, &vnode->flags) && - vnode->cb_expires_at - 10 > now) { - valid = true; - } else if (!test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags) && - vnode->cb_expires_at - 10 > now) { + (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags) || + vnode->cb_expires_at - 10 <= now)) { + valid = false; + } else if (test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags) || + vnode->cb_expires_at - 10 <= now) { + valid = false; + } else { valid = true; } } else if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { valid = true; + } else { + vnode->cb_s_break = vnode->cb_interest->server->cb_s_break; + vnode->cb_v_break = vnode->volume->cb_v_break; + valid = false; } read_sequnlock_excl(&vnode->cb_lock); -- 2.19.1