From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Eddie James <eajames@linux.ibm.com>,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 5.18 042/102] hwmon: (occ) Prevent power cap command overwriting poll response
Date: Tue, 5 Jul 2022 13:58:08 +0200 [thread overview]
Message-ID: <20220705115619.605657758@linuxfoundation.org> (raw)
In-Reply-To: <20220705115618.410217782@linuxfoundation.org>
From: Eddie James <eajames@linux.ibm.com>
commit 1bbb2809040a1f9c7c53c9f06c21aa83275ed27b upstream.
Currently, the response to the power cap command overwrites the
first eight bytes of the poll response, since the commands use
the same buffer. This means that user's get the wrong data between
the time of sending the power cap and the next poll response update.
Fix this by specifying a different buffer for the power cap command
response.
Fixes: 5b5513b88002 ("hwmon: Add On-Chip Controller (OCC) hwmon driver")
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20220628203029.51747-1-eajames@linux.ibm.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/hwmon/occ/common.c | 5 +++--
drivers/hwmon/occ/common.h | 3 ++-
drivers/hwmon/occ/p8_i2c.c | 13 +++++++------
drivers/hwmon/occ/p9_sbe.c | 7 +++----
4 files changed, 15 insertions(+), 13 deletions(-)
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -145,7 +145,7 @@ static int occ_poll(struct occ *occ)
cmd[6] = 0; /* checksum lsb */
/* mutex should already be locked if necessary */
- rc = occ->send_cmd(occ, cmd, sizeof(cmd));
+ rc = occ->send_cmd(occ, cmd, sizeof(cmd), &occ->resp, sizeof(occ->resp));
if (rc) {
occ->last_error = rc;
if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD)
@@ -182,6 +182,7 @@ static int occ_set_user_power_cap(struct
{
int rc;
u8 cmd[8];
+ u8 resp[8];
__be16 user_power_cap_be = cpu_to_be16(user_power_cap);
cmd[0] = 0; /* sequence number */
@@ -198,7 +199,7 @@ static int occ_set_user_power_cap(struct
if (rc)
return rc;
- rc = occ->send_cmd(occ, cmd, sizeof(cmd));
+ rc = occ->send_cmd(occ, cmd, sizeof(cmd), resp, sizeof(resp));
mutex_unlock(&occ->lock);
--- a/drivers/hwmon/occ/common.h
+++ b/drivers/hwmon/occ/common.h
@@ -96,7 +96,8 @@ struct occ {
int powr_sample_time_us; /* average power sample time */
u8 poll_cmd_data; /* to perform OCC poll command */
- int (*send_cmd)(struct occ *occ, u8 *cmd, size_t len);
+ int (*send_cmd)(struct occ *occ, u8 *cmd, size_t len, void *resp,
+ size_t resp_len);
unsigned long next_update;
struct mutex lock; /* lock OCC access */
--- a/drivers/hwmon/occ/p8_i2c.c
+++ b/drivers/hwmon/occ/p8_i2c.c
@@ -111,7 +111,8 @@ static int p8_i2c_occ_putscom_be(struct
be32_to_cpu(data1));
}
-static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
+static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
+ void *resp, size_t resp_len)
{
int i, rc;
unsigned long start;
@@ -120,7 +121,7 @@ static int p8_i2c_occ_send_cmd(struct oc
const long wait_time = msecs_to_jiffies(OCC_CMD_IN_PRG_WAIT_MS);
struct p8_i2c_occ *ctx = to_p8_i2c_occ(occ);
struct i2c_client *client = ctx->client;
- struct occ_response *resp = &occ->resp;
+ struct occ_response *or = (struct occ_response *)resp;
start = jiffies;
@@ -151,7 +152,7 @@ static int p8_i2c_occ_send_cmd(struct oc
return rc;
/* wait for OCC */
- if (resp->return_status == OCC_RESP_CMD_IN_PRG) {
+ if (or->return_status == OCC_RESP_CMD_IN_PRG) {
rc = -EALREADY;
if (time_after(jiffies, start + timeout))
@@ -163,7 +164,7 @@ static int p8_i2c_occ_send_cmd(struct oc
} while (rc);
/* check the OCC response */
- switch (resp->return_status) {
+ switch (or->return_status) {
case OCC_RESP_CMD_IN_PRG:
rc = -ETIMEDOUT;
break;
@@ -192,8 +193,8 @@ static int p8_i2c_occ_send_cmd(struct oc
if (rc < 0)
return rc;
- data_length = get_unaligned_be16(&resp->data_length);
- if (data_length > OCC_RESP_DATA_BYTES)
+ data_length = get_unaligned_be16(&or->data_length);
+ if ((data_length + 7) > resp_len)
return -EMSGSIZE;
/* fetch the rest of the response data */
--- a/drivers/hwmon/occ/p9_sbe.c
+++ b/drivers/hwmon/occ/p9_sbe.c
@@ -78,11 +78,10 @@ done:
return notify;
}
-static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
+static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
+ void *resp, size_t resp_len)
{
- struct occ_response *resp = &occ->resp;
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
- size_t resp_len = sizeof(*resp);
int rc;
rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
@@ -96,7 +95,7 @@ static int p9_sbe_occ_send_cmd(struct oc
return rc;
}
- switch (resp->return_status) {
+ switch (((struct occ_response *)resp)->return_status) {
case OCC_RESP_CMD_IN_PRG:
rc = -ETIMEDOUT;
break;
next prev parent reply other threads:[~2022-07-05 12:31 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-05 11:57 [PATCH 5.18 000/102] 5.18.10-rc1 review Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 001/102] drm/amdgpu: fix adev variable used in amdgpu_device_gpu_recover() Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 002/102] Revert "drm/amdgpu/display: set vblank_disable_immediate for DC" Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 003/102] drm/amdgpu: To flush tlb for MMHUB of RAVEN series Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 004/102] ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 005/102] ksmbd: check invalid FileOffset and BeyondFinalZero " Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 006/102] ksmbd: use vfs_llseek instead of dereferencing NULL Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 007/102] ipv6: take care of disable_policy when restoring routes Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 008/102] net: phy: Dont trigger state machine while in suspend Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 009/102] s390/archrandom: simplify back to earlier design and initialize earlier Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 010/102] nvme-pci: add NVME_QUIRK_BOGUS_NID for ADATA XPG SX6000LNP (AKA SPECTRIX S40G) Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 011/102] nvme-pci: add NVME_QUIRK_BOGUS_NID for ADATA IM2P33F8ABR1 Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 012/102] nvdimm: Fix badblocks clear off-by-one error Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 013/102] ceph: wait on async create before checking caps for syncfs Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 014/102] parisc: Fix vDSO signal breakage on 32-bit kernel Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 015/102] parisc/unaligned: Fix emulate_ldw() breakage Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 016/102] powerpc/prom_init: Fix kernel config grep Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 017/102] powerpc/book3e: Fix PUD allocation size in map_kernel_page() Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 018/102] powerpc/bpf: Fix use of user_pt_regs in uapi Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 019/102] cpufreq: amd-pstate: Add resume and suspend callbacks Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 020/102] dm raid: fix accesses beyond end of raid member array Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 021/102] dm raid: fix KASAN warning in raid5_add_disks Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 022/102] SUNRPC: Fix READ_PLUS crasher Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 023/102] net: rose: fix UAF bugs caused by timer handler Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 024/102] net: usb: ax88179_178a: Fix packet receiving Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 025/102] virtio-net: fix race between ndo_open() and virtio_device_ready() Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 026/102] selftests/net: pass ipv6_args to udpgso_benchs IPv6 TCP test Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 027/102] net: dsa: bcm_sf2: force pause link settings Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 028/102] net: tun: unlink NAPI from device on destruction Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 029/102] net: tun: stop NAPI when detaching queues Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 030/102] net: fix IFF_TX_SKB_NO_LINEAR definition Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 031/102] net: dp83822: disable false carrier interrupt Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 032/102] net: dp83822: disable rx error interrupt Greg Kroah-Hartman
2022-07-05 11:57 ` [PATCH 5.18 033/102] RDMA/qedr: Fix reporting QP timeout attribute Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 034/102] RDMA/cm: Fix memory leak in ib_cm_insert_listen Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 035/102] linux/dim: Fix divide by 0 in RDMA DIM Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 036/102] net: usb: asix: do not force pause frames support Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 037/102] usbnet: fix memory allocation in helpers Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 038/102] mptcp: fix race on unaccepted mptcp sockets Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 039/102] selftests: mptcp: more stable diag tests Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 040/102] mptcp: fix conflict with <netinet/in.h> Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 041/102] selftests: mptcp: Initialize variables to quiet gcc 12 warnings Greg Kroah-Hartman
2022-07-05 11:58 ` Greg Kroah-Hartman [this message]
2022-07-05 11:58 ` [PATCH 5.18 043/102] net: ipv6: unexport __init-annotated seg6_hmac_net_init() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 044/102] NFS: restore module put when manager exits Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 045/102] NFSD: restore EINVAL error translation in nfsd_commit() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 046/102] NFSv4: Add an fattr allocation to _nfs4_discover_trunking() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 047/102] vfs: fix copy_file_range() regression in cross-fs copies Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 048/102] caif_virtio: fix race between virtio_device_ready() and ndo_open() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 049/102] io_uring: ensure that send/sendmsg and recv/recvmsg check sqe->ioprio Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 050/102] PM / devfreq: exynos-ppmu: Fix refcount leak in of_get_devfreq_events Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 051/102] lib/sbitmap: Fix invalid loop in __sbitmap_queue_get_batch() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 052/102] vdpa/mlx5: Update Control VQ callback information Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 053/102] s390: remove unneeded select BUILD_BIN2C Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 054/102] netfilter: nft_dynset: restore set element counter when failing to update Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 055/102] net/dsa/hirschmann: Add missing of_node_get() in hellcreek_led_setup() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 056/102] net/sched: act_api: Notify user space if any actions were flushed before error Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 057/102] net: asix: fix "cant send until first packet is send" issue Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 058/102] net: bonding: fix possible NULL deref in rlb code Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 059/102] net: phy: ax88772a: fix lost pause advertisement configuration Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 060/102] selftests net: fix kselftest net fatal error Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 061/102] net: bonding: fix use-after-free after 802.3ad slave unbind Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 062/102] net: dsa: felix: fix race between reading PSFP stats and port stats Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 063/102] powerpc/memhotplug: Add add_pages override for PPC Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 064/102] platform/x86: thinkpad_acpi: Fix a memory leak of EFCH MMIO resource Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 065/102] platform/x86: ideapad-laptop: Add Ideapad 5 15ITL05 to ideapad_dytc_v4_allow_table[] Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 066/102] nfc: nfcmrvl: Fix irq_of_parse_and_map() return value Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 067/102] NFC: nxp-nci: Dont issue a zero length i2c_master_read() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 068/102] tipc: move bc link creation back to tipc_node_create Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 069/102] epic100: fix use after free on rmmod Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 070/102] cpufreq: qcom-hw: Dont do lmh things without a throttle interrupt Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 071/102] tcp: add a missing nf_reset_ct() in 3WHS handling Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 072/102] nvmet-tcp: fix regression in data_digest calculation Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 073/102] ACPI: video: Change how we determine if brightness key-presses are handled Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 074/102] tunnels: do not assume mac header is set in skb_tunnel_check_pmtu() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 075/102] fanotify: refine the validation checks on non-dir inode mask Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 076/102] nvmet: add a clear_ids attribute for passthru targets Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 077/102] ipv6/sit: fix ipip6_tunnel_get_prl return value Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 078/102] ipv6: fix lockdep splat in in6_dump_addrs() Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 079/102] mlxsw: spectrum_router: Fix rollback in tunnel next hop init Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 080/102] net: tun: avoid disabling NAPI twice Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 081/102] cifs: fix minor compile warning Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 082/102] drm/msm/dpu: Increment vsync_cnt before waking up userspace Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 083/102] platform/x86: ideapad-laptop: Add allow_v4_dytc module parameter Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 084/102] drm/i915/gem: add missing else Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 085/102] drm/i915/dgfx: Disable d3cold at gfx root port Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 086/102] drm/msm/gem: Fix error return on fence id alloc fail Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 087/102] drivers: cpufreq: Add missing of_node_put() in qoriq-cpufreq.c Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 088/102] platform/x86: panasonic-laptop: de-obfuscate button codes Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 089/102] platform/x86: panasonic-laptop: sort includes alphabetically Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 090/102] platform/x86: panasonic-laptop: revert "Resolve hotkey double trigger bug" Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 091/102] platform/x86: panasonic-laptop: dont report duplicate brightness key-presses Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 092/102] platform/x86: panasonic-laptop: filter out duplicate volume up/down/mute keypresses Greg Kroah-Hartman
2022-07-05 11:58 ` [PATCH 5.18 093/102] drm/fourcc: fix integer type usage in uapi header Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 094/102] net: sparx5: Add handling of host MDB entries Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 095/102] net: sparx5: mdb add/del handle non-sparx5 devices Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 096/102] hwmon: (ibmaem) dont call platform_device_del() if platform_device_add() fails Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 097/102] xen/blkfront: fix leaking data in shared pages Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 098/102] xen/netfront: " Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 099/102] xen/netfront: force data bouncing when backend is untrusted Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 100/102] xen/blkfront: " Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 101/102] xen-netfront: restore __skb_queue_tail() positioning in xennet_get_responses() Greg Kroah-Hartman
2022-07-05 11:59 ` [PATCH 5.18 102/102] xen/arm: Fix race in RB-tree based P2M accounting Greg Kroah-Hartman
2022-07-05 14:35 ` [PATCH 5.18 000/102] 5.18.10-rc1 review Jon Hunter
2022-07-05 17:06 ` Justin Forbes
2022-07-05 17:31 ` Fenil Jain
2022-07-05 18:55 ` Florian Fainelli
2022-07-05 20:57 ` Ron Economos
2022-07-06 6:17 ` Naresh Kamboju
2022-07-06 9:39 ` Rudi Heitbaum
2022-07-06 10:13 ` Sudip Mukherjee (Codethink)
2022-07-06 13:45 ` Guenter Roeck
2022-07-06 23:52 ` Shuah Khan
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=20220705115619.605657758@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=eajames@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--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