Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1027037ybe; Wed, 4 Sep 2019 11:21:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhWgxoHLsJhN3sExGBEiTiShmoFeAFKmYUyqqsVgV6miOdtAR54nuq8XL6BeJj9JzRF9WG X-Received: by 2002:aa7:93a8:: with SMTP id x8mr15150689pff.151.1567621289014; Wed, 04 Sep 2019 11:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621289; cv=none; d=google.com; s=arc-20160816; b=MibEC1ZGy5sSsVvHPTCGlcux22RMfLzOfK0/AG60DznbkzaXfaMiLhK0X/cU4MUZYA qzVRogcMfmbdxJT3bIjEY/oV3q9eXYtXDcP29SDdrJBCQ/YZ/baGQefRn+xTQD7hLw+j nK7nDbtkBVh6ok8p5jMqS2QjIdRGhS+rrwzd4ZoRCl8XXyJl+UruIgQZMDvFMC/26md+ DgNEN08V95PfHJHhhAdM4WEsSLZn+kg4T7khQYlul96I4HrvYn3/CgnOWj6bXVD/YTL1 i4EyHlW61wxB8OEeb2Q52bMvNjuSAb7fvCxfuAcKHwz/KAkqLcviREUBkERU4IVeYk+q nhKQ== 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=88brlDd+hcaFP/1dL3CKZ8o+9T0I40Rh3FtmYkqoTbE=; b=Qnvwdakq9SOc4aRcEsMNGia7Tedyz1/akzVBKJLN8T7DxGMOIKJdv+Q5ocBdo/srfI 0PUMwOukEE5K0n/NtVC7sgbBTgQjfhNJzbWvwAefM9xMPlnS8Ya5+hNK/lWkdhlS7lBA 2YXiZNQ/ZsQTzERpiJ4TvbBfXIMWkh18L2q1yvmbSSSqT7Uz987cY3c6BVU9Ouo7mUqk RDqbXLC69Uf0VO2Tnfr+Edsf5KNUP1ASzMCzSfpiaacPHrPgFTYB/NGyW2BEDr2wUOsA O9iC3n8aSZMvn1HVLLsyTMd7Mres2LLUoZSq2omqEMNg7xuJEI/oGuOsJIIRQ53eBL/F R3XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BEMU8gqC; 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 c18si12192480pgp.25.2019.09.04.11.21.10; Wed, 04 Sep 2019 11:21:29 -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=BEMU8gqC; 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 S2389957AbfIDSJf (ORCPT + 99 others); Wed, 4 Sep 2019 14:09:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:52694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389936AbfIDSJ0 (ORCPT ); Wed, 4 Sep 2019 14:09:26 -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 D0C36208E4; Wed, 4 Sep 2019 18:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620566; bh=5u3z1KOs8QFwmpFoypdFi5zGCT8c+6Kam+DDyPLb1Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BEMU8gqC3PM05oR0Tnp0FEopjzzLhCVZUgS27jblFus2FKuAS6c5ZK4FYlLzE/IxT lQI9I+s590oLNl4oReiyN31bFMQB47DRhK+dfeNWlMXK5aLlabKrYCCbAdPuvIRxN5 nIvtMl6+UiJZ4PavZSniga4+XSe4zkmbCg2rVK4Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Dionne , David Howells , Jeffrey Altman , Sasha Levin Subject: [PATCH 5.2 004/143] afs: Fix loop index mixup in afs_deliver_vl_get_entry_by_name_u() Date: Wed, 4 Sep 2019 19:52:27 +0200 Message-Id: <20190904175314.350813503@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@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 [ Upstream commit 4a46fdba449a5cd890271df5a9e23927d519ed00 ] afs_deliver_vl_get_entry_by_name_u() scans through the vl entry received from the volume location server and builds a return list containing the sites that are currently valid. When assigning values for the return list, the index into the vl entry (i) is used rather than the one for the new list (entry->nr_server). If all sites are usable, this works out fine as the indices will match. If some sites are not valid, for example if AFS_VLSF_DONTUSE is set, fs_mask and the uuid will be set for the wrong return site. Fix this by using entry->nr_server as the index into the arrays being filled in rather than i. This can lead to EDESTADDRREQ errors if none of the returned sites have a valid fs_mask. Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation") Signed-off-by: Marc Dionne Signed-off-by: David Howells Reviewed-by: Jeffrey Altman Signed-off-by: Sasha Levin --- fs/afs/vlclient.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index d7e0fd3c00df9..cfb0ac4bd039e 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -56,23 +56,24 @@ static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call) struct afs_uuid__xdr *xdr; struct afs_uuid *uuid; int j; + int n = entry->nr_servers; tmp = ntohl(uvldb->serverFlags[i]); if (tmp & AFS_VLSF_DONTUSE || (new_only && !(tmp & AFS_VLSF_NEWREPSITE))) continue; if (tmp & AFS_VLSF_RWVOL) { - entry->fs_mask[i] |= AFS_VOL_VTM_RW; + entry->fs_mask[n] |= AFS_VOL_VTM_RW; if (vlflags & AFS_VLF_BACKEXISTS) - entry->fs_mask[i] |= AFS_VOL_VTM_BAK; + entry->fs_mask[n] |= AFS_VOL_VTM_BAK; } if (tmp & AFS_VLSF_ROVOL) - entry->fs_mask[i] |= AFS_VOL_VTM_RO; - if (!entry->fs_mask[i]) + entry->fs_mask[n] |= AFS_VOL_VTM_RO; + if (!entry->fs_mask[n]) continue; xdr = &uvldb->serverNumber[i]; - uuid = (struct afs_uuid *)&entry->fs_server[i]; + uuid = (struct afs_uuid *)&entry->fs_server[n]; uuid->time_low = xdr->time_low; uuid->time_mid = htons(ntohl(xdr->time_mid)); uuid->time_hi_and_version = htons(ntohl(xdr->time_hi_and_version)); -- 2.20.1