From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 216AD218E91 for ; Mon, 8 Dec 2025 02:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765162427; cv=none; b=nBG2DFoq5EpbyKVKaYhSdiD/mU60LfoiDRQT76qk4YlQMOY8Sk3Kn/l2cM9KgUl7G2/gGEhEJkDPPCWTWosiaDNJtn0k0r6XzgQQU42k28MnUXO2kX6TV+GWH7KKKws3EdZkfhCUe9q7NTU6I9y7nFeMH2J8avOfGi5s1N/VOks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765162427; c=relaxed/simple; bh=ZpWZDhkk+7rWx7ICEOZReOYbr+Pt63KR9LXvM+11gFE=; h=Date:Mime-Version:Message-ID:Subject:From:Cc:Content-Type; b=SFipDR54pFl6sxXdyPS+Qpp6MZB1DpUT0+Pq1Ob31LtSZ1PrhlOnTHX2SRv+PU8mSRVUuVyzkHjFO1suV7ew0c3bd3D0FRcdwcxwK+0QzGJ0tri/q/zb5rqsVr3yAW5kYp2b5uip+kt6jEvH4X+NVrrzWRbWH/dm13Mt8p9Mwpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--powenkao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DN6UuvNL; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--powenkao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DN6UuvNL" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7b82c2c2ca2so6851787b3a.1 for ; Sun, 07 Dec 2025 18:53:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765162425; x=1765767225; darn=vger.kernel.org; h=cc:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bxUo58ZCKYrBDXm2pU0qHMkvU2xylaPbcjw+LEaUZ+Y=; b=DN6UuvNLCdv5aod8icvmQt0upfRcxn0zbARDikUBfMOj1n2YAAI7DgfRvnsoiQm79Q QByVn6/Uyyv1tcbhyX5SFqwhJpsaRyzSyuY5Dc5VdXEn1xylEv18cy+qA+/7JRg9mIZV miSwFugVHOSv66DundGaZZl34F/fIx9yjOKHvnYpN2YTpmq5O+e4QjvVZbaRNCmdYZw6 QngjOPd+keBujuX52os3Le41umBrspC3fO+h8xhYSnwkcbgb+kWr0AJrfODJX/ZLZnDT lc1oiNts9EkKS49RT/RdhTaLxJRwQSwdpoDoPrpYb1PLL7dR534MppVCHTLKdEQhLaA/ b/cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765162425; x=1765767225; h=cc:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bxUo58ZCKYrBDXm2pU0qHMkvU2xylaPbcjw+LEaUZ+Y=; b=CrDnx1w5u1xk6ElyfTCN3ITWo5fTFTrsjLtMWUC0AX3qjwqd59UQhEMTGYoWQKQPVk ga49aOOvmb+jGd5JkvPH0WPoDKMl0dGAF68v3WIBgNpIvuicyhGchZrGsGn/iKik7ve7 omrSBYv2dedTSEfY9OrNt3wRI5T03cjdcfa6M4MgCNZxv3gKMWkZl0rF1CXELTnXEsWu RKxo8qdeLiCAhonthEIYJ8ccepq31YFIkYXLD93Pff/ettwEVXu6KpJ/qeRKhTWPiNWp PLEmg0GCtVMDnvNmylUTmYeCL3+hwZyK8fTm0DtfEmmUYfNQrUQuKxXZlbG4txZWwGau vgQw== X-Forwarded-Encrypted: i=1; AJvYcCUzUZ+RMblA7B1Vizh4uQMNa1iDF65F4rdfgoBMxF2y6xbCp9MgbghMe8RXvln0QWwp4bvcq/M4a4CQnn4=@vger.kernel.org X-Gm-Message-State: AOJu0YwmR7sPqRzN6x5EDibSGHfnPYe60r+g1h3qm1bcLJ/321VJuvQC BVWqk/cNYOdkQ1if4hMS2W0nPirH4XQbm8N3tKj4uOtXL7K3hVdoaN40vOaiF6z2f84IKjPHVM8 hTncYRFai8josCg== X-Google-Smtp-Source: AGHT+IH8E/s73JksrRT/edTOWaGPyf+3c563oPKWpaMDulDhGCZ6z+1fc5ggXHc0btqo4hA/Nwlu/ZGMqTcNJQ== X-Received: from pgdn16.prod.google.com ([2002:a63:8f10:0:b0:bc7:da10:b2c8]) (user=powenkao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:999f:b0:35d:d477:a7d6 with SMTP id adf61e73a8af0-36617e37c5fmr6500063637.13.1765162425270; Sun, 07 Dec 2025 18:53:45 -0800 (PST) Date: Mon, 8 Dec 2025 02:52:21 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251208025232.4068621-1-powenkao@google.com> Subject: [PATCH 1/1] scsi: ufs: core: Fix error handler encryption support From: Po-Wen Kao Cc: Brian Kao , Alim Akhtar , Avri Altman , Bart Van Assche , "James E.J. Bottomley" , "Martin K. Petersen" , "open list:UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER" , open list Content-Type: text/plain; charset="UTF-8" From: Brian Kao The UFS driver utilizes block layer crypto fields, such as rq->crypt_keyslot and rq->crypt_ctx, to configure hardware for inline encryption. However, the SCSI error handler (EH) reuses the Protocol Data Unit (PDU) from the original failing request when issuing EH commands (e.g., TEST UNIT READY, START STOP UNIT). This can lead to issues if the original request of reused PDU contains stale cryptographic configurations, which are not applicable for the simple EH commands. These commands should not involve data encryption. This patch fixes this by checking if the command was submitted by the SCSI error handler. If so, it bypasses the cryptographic setup for the request, ensuring UTRDs are not inadvertently configured with potentially incorrect encryption parameters. Signed-off-by: Brian Kao --- drivers/ufs/core/ufshcd-crypto.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd-crypto.h b/drivers/ufs/core/ufshcd-crypto.h index c148a5194378..26a0699c8412 100644 --- a/drivers/ufs/core/ufshcd-crypto.h +++ b/drivers/ufs/core/ufshcd-crypto.h @@ -16,7 +16,12 @@ static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, struct ufshcd_lrb *lrbp) { - if (!rq || !rq->crypt_keyslot) { + /* + * Do not use the crypto settings if the SCSI error handler has replaced + * the SCSI command + */ + if (!rq || !rq->crypt_keyslot || + unlikely(lrbp->cmd->submitter == SUBMITTED_BY_SCSI_ERROR_HANDLER)) { lrbp->crypto_key_slot = -1; return; } -- 2.52.0.223.gf5cc29aaa4-goog