Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Damien Le Moal <dlemoal@kernel.org>,
	Niklas Cassel <cassel@kernel.org>, Hannes Reinecke <hare@suse.de>,
	Sasha Levin <sashal@kernel.org>,
	linux-ide@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 11/15] ata: libata-sata: Disallow changing LPM state if not supported
Date: Sun,  3 Aug 2025 17:22:01 -0400	[thread overview]
Message-ID: <20250803212206.3548990-11-sashal@kernel.org> (raw)
In-Reply-To: <20250803212206.3548990-1-sashal@kernel.org>

From: Damien Le Moal <dlemoal@kernel.org>

[ Upstream commit 413e800cadbf67550d76c77c230b2ecd96bce83a ]

Modify ata_scsi_lpm_store() to return an error if a user attempts to set
a link power management policy for a port that does not support LPM,
that is, ports flagged with ATA_FLAG_NO_LPM.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20250701125321.69496-6-dlemoal@kernel.org
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

Based on my analysis of the commit and the surrounding code context,
here's my determination:

**Backport Status: YES**

This commit should be backported to stable kernel trees for the
following reasons:

1. **Fixes a clear bug**: Without this check, users can attempt to
   change LPM policy on ports that don't support LPM (flagged with
   ATA_FLAG_NO_LPM), which could lead to undefined behavior or system
   issues. The code already prevents setting the policy but doesn't
   inform the user that the operation failed.

2. **User-visible issue**: The bug allows sysfs writes to succeed
   silently when they should fail with an error. This violates the
   principle of least surprise - users expect operations to either
   succeed or return an error, not silently fail.

3. **Small and contained fix**: The patch adds just 5 lines of code
   (lines 927-930) that perform a simple flag check and return
   -EOPNOTSUPP if the port doesn't support LPM. This is a minimal change
   with low risk of regression.

4. **Consistency with existing checks**: The function already has
   similar validation for device-level quirks (ATA_QUIRK_NOLPM at lines
   934-937). This patch adds the missing port-level validation, making
   the code more consistent and complete.

5. **Related to recent fixes**: Looking at recent commits (65b2c92f69d3,
   4edf1505b76d), there's been work to properly handle ports that don't
   support LPM. This patch completes that work by ensuring the sysfs
   interface properly rejects invalid operations.

6. **Prevents potential hardware issues**: Attempting to set LPM
   policies on hardware that doesn't support them could potentially
   cause hardware malfunctions or unexpected behavior. This fix prevents
   such attempts at the sysfs interface level.

The fix follows stable kernel rules: it's a clear bug fix, minimal in
scope, doesn't introduce new features, and addresses a real user-facing
issue where invalid operations appear to succeed when they should fail
with an appropriate error code.

 drivers/ata/libata-sata.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 04bdd53abf20..7cacb2bfc360 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -815,6 +815,11 @@ static ssize_t ata_scsi_lpm_store(struct device *device,
 
 	spin_lock_irqsave(ap->lock, flags);
 
+	if (ap->flags & ATA_FLAG_NO_LPM) {
+		count = -EOPNOTSUPP;
+		goto out_unlock;
+	}
+
 	ata_for_each_link(link, ap, EDGE) {
 		ata_for_each_dev(dev, &ap->link, ENABLED) {
 			if (dev->horkage & ATA_HORKAGE_NOLPM) {
-- 
2.39.5


  parent reply	other threads:[~2025-08-03 21:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-03 21:21 [PATCH AUTOSEL 5.15 01/15] hfs: fix slab-out-of-bounds in hfs_bnode_read() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 02/15] hfsplus: fix slab-out-of-bounds in hfsplus_bnode_read() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 03/15] hfsplus: fix slab-out-of-bounds read in hfsplus_uni2asc() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 04/15] hfsplus: don't use BUG_ON() in hfsplus_create_attributes_file() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 05/15] arm64: Handle KCOV __init vs inline mismatches Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 06/15] smb/server: avoid deadlock when linking with ReplaceIfExists Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 07/15] udf: Verify partition map count Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 08/15] drbd: add missing kref_get in handle_write_conflicts Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 09/15] hfs: fix not erasing deleted b-tree node issue Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 10/15] better lockdep annotations for simple_recursive_removal() Sasha Levin
2025-08-03 21:22 ` Sasha Levin [this message]
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 12/15] fs/ntfs3: Add sanity check for file name Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 13/15] fs/ntfs3: correctly create symlink for relative path Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 14/15] ext2: Handle fiemap on empty files to prevent EINVAL Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 15/15] securityfs: don't pin dentries twice, once is enough Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250803212206.3548990-11-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=hare@suse.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox