From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384568; b=qPKxBexEYrjRbRhG2BHSFL8vbzlhN9KdClLlCoByyiJNc03CmQlq0lFlI5kj9HtdeVkS 4o1BO6nJYXMigxJUvam55PK+BONCoufeWCz/3AmoRMewL9VaKvzxZWoiDuzGUBl0hXVBo XlfVbKC8M6OD3jIZVvds3pH2uQoPgysHluzuD0H0W+b1z+CEhjA7VBQc6p0jEy5/PUwuE lr/7chN3874d23ARlihv/8fh7MJgojK2AJtmYG2tJRJ39LWtILseWauzJ0hgxgOUndDfE x8U/4X8jU+PZPolmfEiTxgy3fUXRqiyGvjEjgR9EgzmfXLeeftcrqHxgnm4fjIPNCrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384568; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=vvN/JgdAQSMownQeAR1mFZq6R0+CQ73cRlZNtkz4E/E=; b=QTYR+vZ2beF1CAjIEiclragZfAkFbWT4UO6ONv3sOx+l8SaGl3b4QyqD8xK7lV/K+NCv bkHbOS2EZ9M7RCPoYRoNNlfa1WbmQmVO9/n8JAASpP5dNmx1BPG+CE2LIqDGkSlj9TYup +E7vdK0a7rpTa52+MEJ/8yboSiJkZjG3+KXHgjHgbbDU14qBISkCt52pbOAHI3YRCHO2Y ru7+o8MxfY2YQhf5z15qIZDosMpUw6KhWNXSC0iokBqVcZRhYwEQ9acSFo160Q452W5Lf 97OacCxtTNQOJ2YZK8OpX/FV4aYo3OgmCRm5cmIXPMw1SFLFVIhAkhasDivJ/e4HLHg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VX+e8ls5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEF8F606A322; Fri, 4 Dec 2026 11:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VX+e8ls5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 570D11F000C2; Fri, 4 Dec 2026 11:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384568; bh=vvN/JgdAQSMownQeAR1mFZq6R0+CQ73cRlZNtkz4E/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VX+e8ls5haWlMa1QTCsMiZ7AADYvhlXMWq02rrekAEqYltqaG+Wfns8RApczqUlTE Hgu4R44NgfH2qah/1WpTBSSiZ1IQWaBE+sa/uVgscGyDAnulAYwvZWemZGJs2W972F udHkTKKRAuiWb7tSTEf5Lu+ZSqgX90gQL26l4KvE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Damien Le Moal , Niklas Cassel , Sasha Levin Subject: [PATCH 6.6 0206/1167] ata: libata-scsi: fix MODE SELECT handling of data after the mode page Date: Fri, 4 Dec 2026 18:53:53 +0900 Message-ID: <20261204100707.434490845@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Niklas Cassel [ Upstream commit 6fde0444d07ec954f3d885375e0402ff2f2e5064 ] ata_scsi_mode_select_xlat() only supports one mode page per MODE SELECT command, and rejects a parameter list with data after the mode page with INVALID FIELD IN PARAMETER LIST. However: - It does not set the field pointer, so the sense data reports 0xffff as the FIELD POINTER. - It only checks for data after the mode page after the mode page handler has been called. ata_mselect_control_ata_feature() has then already updated the CDL enabled flag of the device, even though the command is rejected and the CDL setting of the device is not changed. - For the control mode page, ata_mselect_control_spg0() does not need an ATA command, so the check is skipped, and the data after the mode page is silently ignored. Check for data after the mode page before calling the mode page handlers, and set the FIELD POINTER to the first byte after the mode page, i.e. to the first byte of the next mode page. The reason why only one mode page per command is supported is that a MODE SELECT command is translated into at most one ATA command, so update the comment accordingly. Fixes: 1b26d29ccd59 ("[libata] scsi: implement MODE SELECT command") Reviewed-by: Damien Le Moal Link: https://lore.kernel.org/r/20261103205448.931471-11-cassel@kernel.org Signed-off-by: Niklas Cassel Signed-off-by: Sasha Levin --- drivers/ata/libata-scsi.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index b9c6d953af8e6..189c9c1d77208 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -4036,6 +4036,17 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) if (pg_len > len) goto invalid_param_len; + /* + * A MODE SELECT command is translated into at most one ATA command, so + * only one mode page per command is supported. Reject any data after + * the mode page before calling the mode page handlers, which may + * already update the device flags. + */ + if (len > pg_len) { + fp = p - buffer + pg_len; + goto invalid_param; + } + switch (pg) { case CACHE_MPAGE: if (ata_mselect_caching(qc, p, pg_len, &fp) < 0) { @@ -4058,13 +4069,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param; } - /* - * Only one page has changeable data, so we only support setting one - * page at a time. - */ - if (len > pg_len) - goto invalid_param; - return 0; invalid_fld: -- 2.53.0