From: Dan Carpenter <dan.carpenter@linaro.org>
To: Akshay Gupta <akshay.gupta@amd.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
kernel-janitors@vger.kernel.org
Subject: [bug report] misc: amd-sbi: Add support for CPUID protocol
Date: Tue, 27 May 2025 11:05:15 +0300 [thread overview]
Message-ID: <aDVyO8ByVsceybk9@stanley.mountain> (raw)
Hello Akshay Gupta,
Commit bb13a84ed6b7 ("misc: amd-sbi: Add support for CPUID protocol")
from Apr 28, 2025 (linux-next), leads to the following Smatch static
checker warning:
drivers/misc/amd-sbi/rmi-core.c:132 rmi_cpuid_read() warn: bitwise OR is zero '0xffffffff00000000 & 0xffff'
drivers/misc/amd-sbi/rmi-core.c:132 rmi_cpuid_read() warn: potential integer overflow from user 'msg->cpu_in_out << 32'
drivers/misc/amd-sbi/rmi-core.c:213 rmi_mca_msr_read() warn: bitwise OR is zero '0xffffffff00000000 & 0xffff'
drivers/misc/amd-sbi/rmi-core.c:213 rmi_mca_msr_read() warn: potential integer overflow from user 'msg->mcamsr_in_out << 32'
drivers/misc/amd-sbi/rmi-core.c:376 apml_rmi_reg_xfer() warn: maybe return -EFAULT instead of the bytes remaining?
drivers/misc/amd-sbi/rmi-core.c:394 apml_mailbox_xfer() warn: maybe return -EFAULT instead of the bytes remaining?
drivers/misc/amd-sbi/rmi-core.c:411 apml_cpuid_xfer() warn: maybe return -EFAULT instead of the bytes remaining?
drivers/misc/amd-sbi/rmi-core.c:428 apml_mcamsr_xfer() warn: maybe return -EFAULT instead of the bytes remaining?
drivers/misc/amd-sbi/rmi-core.c
110 static int rmi_cpuid_read(struct sbrmi_data *data,
111 struct apml_cpuid_msg *msg)
112 {
113 struct cpu_msr_indata input = {0};
114 struct cpu_msr_outdata output = {0};
115 int val = 0;
116 int ret, hw_status;
117 u16 thread;
118
119 mutex_lock(&data->lock);
120 /* cache the rev value to identify if protocol is supported or not */
121 if (!data->rev) {
122 ret = sbrmi_get_rev(data);
123 if (ret < 0)
124 goto exit_unlock;
125 }
126 /* CPUID protocol for REV 0x10 is not supported*/
127 if (data->rev == 0x10) {
128 ret = -EOPNOTSUPP;
129 goto exit_unlock;
130 }
131
132 thread = msg->cpu_in_out << CPUID_MCA_THRD_INDEX & CPUID_MCA_THRD_MASK;
CPUID_MCA_THRD_INDEX is 32.
CPUID_MCA_THRD_MASK is 0xffff.
Smatch complains that msg->cpu_in_out is user data but we're shifting
away some bits which is suspicious (but can be fine). But then the
result of the shift mask we save in thread is always zero.
133
134 /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */
135 if (thread > 127) {
136 thread -= 128;
137 val = 1;
138 }
139 ret = regmap_write(data->regmap, SBRMI_THREAD128CS, val);
140 if (ret < 0)
141 goto exit_unlock;
142
143 prepare_cpuid_input_message(&input, thread,
144 msg->cpu_in_out & CPUID_MCA_FUNC_MASK,
Maybe it was suppoesd to be just "& CPUID_MCA_FUNC_MASK" without the
shift?
145 msg->cpu_in_out >> CPUID_EXT_FUNC_INDEX);
146
147 ret = regmap_bulk_write(data->regmap, CPUID_MCA_CMD,
148 &input, CPUID_WR_REG_LEN);
149 if (ret < 0)
[ snip ]
353 static int apml_rmi_reg_xfer(struct sbrmi_data *data,
354 struct apml_reg_xfer_msg __user *arg)
355 {
356 struct apml_reg_xfer_msg msg = { 0 };
357 unsigned int data_read;
358 int ret;
359
360 /* Copy the structure from user */
361 if (copy_from_user(&msg, arg, sizeof(struct apml_reg_xfer_msg)))
362 return -EFAULT;
363
364 mutex_lock(&data->lock);
365 if (msg.rflag) {
366 ret = regmap_read(data->regmap, msg.reg_addr, &data_read);
367 if (!ret)
368 msg.data_in_out = data_read;
369 } else {
370 ret = regmap_write(data->regmap, msg.reg_addr, msg.data_in_out);
371 }
372
373 mutex_unlock(&data->lock);
374
375 if (msg.rflag && !ret)
376 return copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg));
^^^^^^^^^^^^
copy_to/from_user() returns the number of bytes that it wasn't able to
copy. This should be:
if (ret)
return ret;
if (msg.rflag) {
if (copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg)))
return -EFAULT;
}
return 0;
377 return ret;
378 }
regards,
dan carpenter
next reply other threads:[~2025-05-27 8:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 8:05 Dan Carpenter [this message]
2025-05-27 8:24 ` [bug report] misc: amd-sbi: Add support for CPUID protocol Dan Carpenter
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=aDVyO8ByVsceybk9@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=akshay.gupta@amd.com \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.