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=1796387229; b=EGRBpKnaWpDNa6ex+2f0PNdo45sOmwY6oIMJ+Z86LG/2QyHSu782Za5R9NHTCSDAyZ7r UhlCpsBDzrxQci7buoDxydjoxPAkOh4Y+wFxFCF4Ih2vqVIiFTq6UcVH458BSZsccG6nT 3TYFGJCtdb7c/pdc5/lV/K4q9SFlM5zJZjkCrgwHaNISiHBPuAA1gQtdEID2+rCX9sQZQ VTyGjv3hBwXbNPQrfsK3hE8dey1EBGYra59p+37Nh6Q6tJfmeBxJPH7CC4IUmQqgQVPZR TloIqPIlv+3lmgbErVFoilUYctT8JL0RWacVA/O3i6c4nQU3gYZeyhsgm2dHLvZnmxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387229; 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=XK/U9uDV+peezd0EBVfaPSYcOOyK3BOqcuWo236cTLk=; b=s/mI0tmiBfrnXqf8gvZS/+niU4hSRE3kmo+zL3NitlZjp0iYmxJVdxNKqr50bkazZure PiemDqD992dQ8P2cN/mOljvK1v5CaaxOHJBObOraLFByCb97P5cXOQN4LqWPEioS7WyAt 6YqZgoLb54v+/kBizziSq5IlXJiVP7s+k6aP6NG/sKAKfeEB0L1CIV/E/Gsa4EW+16Nyd HSku+8j99OaofKyNs/3mtASRJb12QDPyItt4E8Ey+UM5Vo699UjHFfOor8AfsXu03VEWm 3DBYT0IYBMNIo3MqzPX9h5MzXh+OWZRzOhz2Gp23oWqUAldmi6syfEEvtbtjivp6EEQ== 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=mUpi0dsD; 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 140C4606A332; Fri, 4 Dec 2026 12:27:09 +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=mUpi0dsD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82F2A1F000CE; Fri, 4 Dec 2026 12:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387228; bh=XK/U9uDV+peezd0EBVfaPSYcOOyK3BOqcuWo236cTLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mUpi0dsDw5wXOK5AVImUHYTi4HSDvVRNnANG5MrMM2KzLUeS7WHHt9FBgOL/Y+nXM 07+Oj1NFGM1pXPG3ctKyrrMkqesYKwYGPLhWRlz8/lNsvCTKMt+b6lwmpQkzTcVXnX EJrrnxI0wPZT3zYx/52ksX1s4n/DOtiPlgjIWZE8= 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.1 0158/1059] ata: libata-scsi: fix MODE SELECT handling of data after the mode page Date: Fri, 4 Dec 2026 18:54:49 +0900 Message-ID: <20261204100648.311830065@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 c9706ca86ac49..abefbcae4e069 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3946,6 +3946,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) { @@ -3966,13 +3977,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