From nobody Tue Sep 29 04:42:43 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 09A3238425A for ; Wed, 12 Aug 2026 09:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786525221; cv=none; b=R8gHzI/IDBSm8qeIU4DaCw2CVMi7b+11Zd5MISSpu3E7qMxC3YKZXQm3zJeot/rDjqNjMos5gPCTgv1dP3RtEWb8u3zQ7G3Eo38WRnRhwP9jNdH4ALm6XagVIjJklWbAf9w61JV6uAECEcs1WgnLyjrxOBWewPKyNaPkQonzMDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786525221; c=relaxed/simple; bh=yqBRs45rJW/f0nLW7fpTNVLvsms8VxpJ9uXllGHL8qI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fxBWFAvFFYIqcjbo0B4J1pYgyiYJB1MzeKigUBYRwe/V0oN3EIim5rpkRw0CbPy7nYkbqSn5JLL97LJgw0BXVgyBK5AO59pTB35E863kQ790RSJxptcnQKdTRBdgf4oIs6FRTAk6JdLhARM0t7co+/+twQWk9yB2EqPEkUPcX3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PdbPIqey; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PdbPIqey" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-84830c774a0so984438b3a.1 for ; Wed, 12 Aug 2026 02:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786525219; x=1787130019; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=xrc/ShWziw9uFMoeJyr/D7LL2jAZid2JLgmjk8Dtuqg=; b=PdbPIqeyujfPQZ//rTzOCq0rXiUEfiTpXNDu2EmdhprFGn7QnnnEem8Bdko1WTNX3z gyWy9IOSthZWeqISlWVr0bRTQNbjkytAtxxitPSErzlHsIuUiNApftpwy8AB7b2Uoc6h 0SQ7LGz1rES2z250csTFwCVkTqMTSQt7lZ1F/Pw8BFh2ru6xeeTeQgspVkgMlZ213flR p7z7gFXWzPSGDdfE+MNipqxmg5U4/g7Fp4TIlaW/CsrSd6gyDotxCBGN5ACk1xrOuFBU q0H9Lr2dloo/7cnMxzIseRYoN3vTFO+rdWPuZAAu+9Npa9HT7cVSrYrhV9XIK46kAFlK Ugaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786525219; x=1787130019; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xrc/ShWziw9uFMoeJyr/D7LL2jAZid2JLgmjk8Dtuqg=; b=EUl5LmLpm7Kuf8s+q3QboKoKLJDOQVkrRlSeqljtUmRa4jmVrsr9yoKuSY8TTC5JKm g4q15WJN/s2F121wgnbZavvQRovf8XaKMNmdIUxNNUWhF955otfeHZ8iUH10SMBMOxFn Bkx9CYU7+C9a1Y4bbPoK0dWFXQ5ymJyYOpWVxP/yvmEiqBDaFPl/51d9GDSpw2NhejZ4 HtaDqCSigUS2erRsAs1l49LZYdrUQQUn0f48vTjj3kX5/S5FcrBUTlJQTwr2nlzzEhEG hbDOrOgp3h/e13N+AMxh1U8SI75iS/F4Zz6/ux7d6c6pjFsuIBmGsYGLmRVuLvtIIq14 vVRw== X-Forwarded-Encrypted: i=1; AHgh+RreDzKEtfU5gaR5JvdgLjzcv3fG5/hR88aVd0m2shbwNRujzwivxPZa6YqJJGFSQ6yACLkQlqUneP7aLkE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywuf/8kUjrsMeq08lVmEBF3ZnsuLxm4JD1OCtuov5H3YuZ0Jeel 3BBCIHz7U4y9qpE8CcpaL2Coy7Wjnah952p3g1LRMrTWOBHn8XxEmM5w9ivNj5cS X-Gm-Gg: AR+sD12E2Q/nfHMQWoaLZXNkSQWx7LrRuGAKus+01mHqsPZ1IFo9rCwTr79S7UTIL8e Hez6eErtF50I2XvBj7oW2gUMWeq7ilLACmxMV+tV0CT0Y7JbuJqa11/2C4hBGtMPRmZfNSO8zGz c4hnG7C7LN+dAwTC4n44k4VIdhl82fBpx7YrpUVgi0Jy8zntpDfPjsny0u47drf3jfLxKb8ENCa VJMMFiuipf/Ny0BUv9c/Vn/zkk9GkqxozVjpnVgbnIXjIN2s+fYTYKw4vUKc/qLqnbUGryghIjn ZewHESsKkD4NQu+9JcffD4i90mtEkfNuWnCLcb+RkWfM8N7pr4u9vDLgYvK7Rm/rWqjx9mgl+4O GouCF7YAmwRp/nHe2loaEA+wYhQ9iUW0HRzOOWEHmyfpU15EjrCzJ0BiUrlQd65RMVaVPWk+xra mYb91kSQbQVDgiIbPl8a+HUkEO+sQkY1FxO2GqNQ83VyxSkQjzSUGel+TBZA+0BXn9nAAxSZV7/ jJMPGAnKTs= X-Received: by 2002:a05:6a20:431c:b0:3be:b0b3:3962 with SMTP id adf61e73a8af0-3cc3f5b35fdmr3946999637.9.1786525219239; Wed, 12 Aug 2026 02:00:19 -0700 (PDT) Received: from volcano9f8e-host.amd.com ([165.204.217.251]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31cf6d726f1sm13571562eec.26.2026.08.12.02.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2026 02:00:18 -0700 (PDT) From: Hemanth Selam To: naveenkrishna.chatradhi@amd.com, hansg@kernel.org, ilpo.jarvinen@linux.intel.com Cc: carlos.bilbao@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] platform/x86/amd/hsmp: Reject negative power cap writes in hwmon Date: Wed, 12 Aug 2026 14:30:12 +0530 Message-ID: <20260812090012.140193-1-hemanth.selam@gmail.com> X-Mailer: git-send-email 2.43.7 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hsmp_hwmon_write() takes the user-supplied hwmon value as a signed long and assigns "val / MICROWATT_PER_MILLIWATT" to msg.args[0], which is a __u32. MICROWATT_PER_MILLIWATT is an unsigned long, so a negative write to power1_cap (e.g. "echo -1 > power1_cap") is first converted to a huge unsigned value by the division and then stored into the u32 argument. As a result a nonsensical, multi-gigawatt socket power limit is sent to the SMU via HSMP_SET_SOCKET_POWER_LIMIT instead of the write being rejected. Reject negative values with -EINVAL before the conversion. Tested with HSMP enabled: CAP=3D$(dirname $(grep -l amd_hsmp_hwmon \ /sys/class/hwmon/hwmon*/name | head -1))/power1_cap # negative write echo -1000000 > $CAP ; echo "ret=3D$?" # valid positive write must still work echo 400000000 > $CAP ; echo "ret=3D$?" Before: # echo -1000000 > $CAP ; echo "ret=3D$?" ret=3D0 <- accepted; bogus limit sent to SMU # echo 400000000 > $CAP ; echo "ret=3D$?" ret=3D0 After: # echo -1000000 > $CAP ; echo "ret=3D$?" bash: echo: write error: Invalid argument ret=3D1 <- rejected with -EINVAL # echo 400000000 > $CAP ; echo "ret=3D$?" ret=3D0 <- valid write still works Fixes: 92c025db52bb ("platform/x86/amd/hsmp: Report power via hwmon sensors= ") Signed-off-by: Hemanth Selam --- drivers/platform/x86/amd/hsmp/hwmon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/platform/x86/amd/hsmp/hwmon.c b/drivers/platform/x86/a= md/hsmp/hwmon.c index 0cc9a742497f..c8314eee06f4 100644 --- a/drivers/platform/x86/amd/hsmp/hwmon.c +++ b/drivers/platform/x86/amd/hsmp/hwmon.c @@ -31,6 +31,9 @@ static int hsmp_hwmon_write(struct device *dev, enum hwmo= n_sensor_types type, if (attr !=3D hwmon_power_cap) return -EOPNOTSUPP; =20 + if (val < 0) + return -EINVAL; + msg.num_args =3D 1; msg.args[0] =3D val / MICROWATT_PER_MILLIWATT; msg.msg_id =3D HSMP_SET_SOCKET_POWER_LIMIT; --=20 2.43.7