Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3337434imu; Sun, 11 Nov 2018 12:40:54 -0800 (PST) X-Google-Smtp-Source: AJdET5eB7ZoP4NajBQFToGHkkfDiy1+4bBSD3hzSHTc+uWqKdMPjA3imoa0V0RWxJ79KS+qcO0z6 X-Received: by 2002:a65:434d:: with SMTP id k13mr2320438pgq.269.1541968854887; Sun, 11 Nov 2018 12:40:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968854; cv=none; d=google.com; s=arc-20160816; b=wDOMJrLDYTKlWC/ScT0QaU4mY4DGFqtHWNYIHuYZYSLtRc4DZ6jX2FfsjHiJWUzQgE EOMYruHcm2W7nCxwilMgyXG5lWorYWLoYuJItr8/LSm/2f65X6Th3Kk/goTcIw/fvihk gDz6I40D+Z6wNZUR5RShCbkOXiklSCKIv98U2TB5NeD1IzxF7jnGPn1XnBctqegourtc fMOwRWXj6JeRueCny/7gyu0/fVne/4JecKdwpr9OCRitYSZxgGtiF5k+aU/er5OLyxNr E5fx2mqlzHXfKjhPoSZ2T3PcHbT4/0ERdBCtk3Z94rQaq80R/IZH6e81ptakwiAlbD7Q NS+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=AOBakQmh/K5fBxBFkWElYYooJHQP8WtPo9l40BS6NZQ=; b=0qotB+QPnypeLXj1lg8Ojt5rDa8QNLibqcytv1sktkONKSiRSerP8jzeQB8ucQ0qyj LvAC6kK5uHouktecG5KmKkt/voRNUUEVpemrHJxokLf+7lW+vGnI/6Pax8lBAO7jvMGa fj2VKfVNepI6zqNFUiRQWUUB91wZWOHUTCCnGDeD2fms3f2DyKnKLBk/Q/Lgd7uNOZqG Etk4TWvCmCC7tvA7ZBE7pbDac+ENWSZqY5hXkgRN7Yg5QoAjA9aoQy5o7LmoFY3EKCik QqLF/LpV65X5tqhLcJpoOVqomKc+FG3YREahdjO0OYHLtgLo/0R1aFC32Qa5ceA++4td lYxg== 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 k8-v6si14172103pgj.192.2018.11.11.12.40.39; Sun, 11 Nov 2018 12:40: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 S1730024AbeKLFsI (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:08 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49560 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729994AbeKLFsH (ORCPT ); Mon, 12 Nov 2018 00:48:07 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsT-0000oJ-AC; Sun, 11 Nov 2018 19:58:37 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsS-0001ZN-Qf; Sun, 11 Nov 2018 19:58:36 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Maged Mokhtar" , "Mike Christie" , "Martin K. Petersen" , "Christoph Hellwig" , "David Disseldorp" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 155/366] scsi: target: Fix truncated PR-in ReadKeys response In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: David Disseldorp commit 63ce3c384db26494615e3c8972bcd419ed71f4c4 upstream. SPC5r17 states that the contents of the ADDITIONAL LENGTH field are not altered based on the allocation length, so always calculate and pack the full key list length even if the list itself is truncated. According to Maged: Yes it fixes the "Storage Spaces Persistent Reservation" test in the Windows 2016 Server Failover Cluster validation suites when having many connections that result in more than 8 registrations. I tested your patch on 4.17 with iblock. This behaviour can be tested using the libiscsi PrinReadKeys.Truncate test. Signed-off-by: David Disseldorp Reviewed-by: Mike Christie Tested-by: Maged Mokhtar Reviewed-by: Christoph Hellwig Signed-off-by: Martin K. Petersen [bwh: Backported to 3.16: Convert from open-coded put_unaligned_be64()] Signed-off-by: Ben Hutchings --- drivers/target/target_core_pr.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -3726,18 +3726,16 @@ core_scsi3_pri_read_keys(struct se_cmd * * Check for overflow of 8byte PRI READ_KEYS payload and * next reservation key list descriptor. */ - if ((add_len + 8) > (cmd->data_length - 8)) - break; - - buf[off++] = ((pr_reg->pr_res_key >> 56) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 48) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 40) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 32) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 24) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 16) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 8) & 0xff); - buf[off++] = (pr_reg->pr_res_key & 0xff); - + if (off + 8 <= cmd->data_length) { + put_unaligned_be64(pr_reg->pr_res_key, &buf[off]); + off += 8; + } + /* + * SPC5r17: 6.16.2 READ KEYS service action + * The ADDITIONAL LENGTH field indicates the number of bytes in + * the Reservation key list. The contents of the ADDITIONAL + * LENGTH field are not altered based on the allocation length + */ add_len += 8; } spin_unlock(&dev->t10_pr.registration_lock);