Received: by 10.223.185.116 with SMTP id b49csp2185323wrg; Thu, 15 Feb 2018 07:47:54 -0800 (PST) X-Google-Smtp-Source: AH8x226vqw3wzU7cXEoQONgl3Yo4WXpDpeN6++WcTrDiM1fbTKLPRZ4nSzvkGj1DCkNz03eRMHrp X-Received: by 2002:a17:902:900b:: with SMTP id a11-v6mr2923859plp.249.1518709674407; Thu, 15 Feb 2018 07:47:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518709674; cv=none; d=google.com; s=arc-20160816; b=jsu0NGiZ2lbt6hVD4+n/k6FnVz/ggV6RMSF91fwDSI2OJ5EZE1TU/PzThEaaGC12Py PqfHOcAE1IaOGSJuYc0nojRdFDpEw5EiuoqrhGKSrt/4vhGK9agfo8ZLidKzP+KPzmqv D6JpIngqn5OXwwxw9nI+Y0qUKUFLy7eQMtiVhDRbcxsCjhqRURMr4H1FqfhMUziO/HzX 7QhHqb8RC6mrp+/G03PBcbPa4ceAaSONu52ySG0SS7742wj9x/HYyZKamQuc2axkZv5t ame+EwUcE5QkTk4BoYC78JO55MAzr19pR/Yf6WBujItjYV+r3zGe5nn2KlZEbQ+tVjzq itwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kAcDUXlyj5uFqXnL/uYxEt3ZKb14YH4KiSGRQehKIGo=; b=OT+3dO08FB81+nWFDhvCgo7Xe4ozaFWl2pdKOilKO832d3rqg436fbTM/vh3bV0dWh 907JgD2zm1xBc4AcMi/mYoYP/3OgR6wZYDL1eqp6RbAh8DwmjWgOdvg0taTwpA9wMn9G pchKUks+HHBVlC3XwYqaIrAyTFgR+oJoAnsEjIUNDcVq7FcGJN5JhAZck3GKIr6CyYxZ KenbdlahqKhg/8O7nLCxLFs4am8b828zGpUK5Fou2VId7HeQM7hUzgqmSlpcdQMCeRVo jr6uYnGzG8rfFyJqf3Tzki4sGEoVVAjgj8gWa2+76/k8wSbe978ER1LQP5M7f40IlPk+ 7ZAQ== ARC-Authentication-Results: i=1; mx.google.com; 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 z78si1323447pfk.374.2018.02.15.07.47.39; Thu, 15 Feb 2018 07:47:54 -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; 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 S1424453AbeBOPpU (ORCPT + 99 others); Thu, 15 Feb 2018 10:45:20 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34862 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424417AbeBOPpM (ORCPT ); Thu, 15 Feb 2018 10:45:12 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 35BC1117F; Thu, 15 Feb 2018 15:45:12 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Dionne , David Howells Subject: [PATCH 4.15 144/202] afs: Fix missing cursor clearance Date: Thu, 15 Feb 2018 16:17:24 +0100 Message-Id: <20180215151720.588481731@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Howells commit fe4d774c847398c2a45c10a780ccfde069840793 upstream. afs_select_fileserver() ends the address cursor it is using in the case in which we get some sort of network error and run out of addresses to iterate through, before it jumps to try the next server. This also needs to be done when the server aborts with some sort of error that means we should try the next server. Fix this by: (1) Move the iterate_address afs_end_cursor() call to the next_server case. (2) End the cursor in the failed case. (3) Make afs_end_cursor() clear the ->begun flag and ->addr pointer in the address cursor. (4) Make afs_end_cursor() able to be called on an already cleared cursor. Without this, something like the following oops may occur: AFS: Assertion failed 18446612134397189888 == 0 is false 0xffff88007c279f00 == 0x0 is false ------------[ cut here ]------------ kernel BUG at fs/afs/rotate.c:360! RIP: 0010:afs_select_fileserver+0x79b/0xa30 [kafs] Call Trace: afs_statfs+0xcc/0x180 [kafs] ? p9_client_statfs+0x9e/0x110 [9pnet] ? _cond_resched+0x19/0x40 statfs_by_dentry+0x6d/0x90 vfs_statfs+0x1b/0xc0 user_statfs+0x4b/0x80 SYSC_statfs+0x15/0x30 SyS_statfs+0xe/0x10 entry_SYSCALL_64_fastpath+0x20/0x83 Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation") Reported-by: Marc Dionne Signed-off-by: David Howells Signed-off-by: Greg Kroah-Hartman --- fs/afs/addr_list.c | 13 ++++++++++--- fs/afs/rotate.c | 12 ++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -332,11 +332,18 @@ bool afs_iterate_addresses(struct afs_ad */ int afs_end_cursor(struct afs_addr_cursor *ac) { - if (ac->responded && ac->index != ac->start) - WRITE_ONCE(ac->alist->index, ac->index); + struct afs_addr_list *alist; - afs_put_addrlist(ac->alist); + alist = ac->alist; + if (alist) { + if (ac->responded && ac->index != ac->start) + WRITE_ONCE(alist->index, ac->index); + afs_put_addrlist(alist); + } + + ac->addr = NULL; ac->alist = NULL; + ac->begun = false; return ac->error; } --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -334,6 +334,7 @@ start: next_server: _debug("next"); + afs_end_cursor(&fc->ac); afs_put_cb_interest(afs_v2net(vnode), fc->cbi); fc->cbi = NULL; fc->index++; @@ -408,16 +409,15 @@ iterate_address: /* Iterate over the current server's address list to try and find an * address on which it will respond to us. */ - if (afs_iterate_addresses(&fc->ac)) { - _leave(" = t"); - return true; - } + if (!afs_iterate_addresses(&fc->ac)) + goto next_server; - afs_end_cursor(&fc->ac); - goto next_server; + _leave(" = t"); + return true; failed: fc->flags |= AFS_FS_CURSOR_STOP; + afs_end_cursor(&fc->ac); _leave(" = f [failed %d]", fc->ac.error); return false; }