tree:
https://github.com/0day-ci/linux/commits/UPDATE-20200613-235004/Borislav-...
head: 24611fae296234f2f3d5e95062d44390a482887b
commit: 24611fae296234f2f3d5e95062d44390a482887b [1/1] x86/msr: Filter MSR writes
config: x86_64-randconfig-c002-20200613 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
All warnings (new ones prefixed by >>, old ones prefixed by <<):
arch/x86/kernel/msr.c: In function 'set_allow_writes':
> arch/x86/kernel/msr.c:281:21: warning: passing argument 1 of
'strstrip' discards 'const' qualifier from pointer target type
[-Wdiscarded-qualifiers]
281 | char *s = strstrip(val);
| ^~~
In file included from include/linux/bitmap.h:9,
from include/linux/cpumask.h:12,
from arch/x86/include/asm/cpumask.h:5,
from arch/x86/include/asm/msr.h:11,
from arch/x86/include/asm/processor.h:22,
from arch/x86/include/asm/cpufeature.h:5,
from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:38,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from include/linux/stat.h:19,
from include/linux/module.h:13,
from arch/x86/kernel/msr.c:22:
include/linux/string.h:76:49: note: expected 'char *' but argument is of type
'const char *'
76 | static inline __must_check char *strstrip(char *str)
| ~~~~~~^~~
In file included from include/linux/compiler_types.h:59,
from <command-line>:
arch/x86/kernel/msr.c: In function 'filter_write':
> include/linux/compiler_attributes.h:200:41: warning: attribute
'fallthrough' not preceding a case label or default label
200 | # define
fallthrough __attribute__((__fallthrough__))
| ^~~~~~~~~~~~~
> arch/x86/kernel/msr.c:86:11: note: in expansion of macro
'fallthrough'
86 | default: fallthrough;
| ^~~~~~~~~~~
vim +281 arch/x86/kernel/msr.c
80
81 static int filter_write(u32 reg)
82 {
83 switch (allow_writes) {
84 case MSR_WRITES_ON: return 0; break;
85 case MSR_WRITES_OFF: return -EPERM; break;
86 default: fallthrough;
87 }
88
89 if (reg == MSR_IA32_ENERGY_PERF_BIAS)
90 return 0;
91
92 pr_err_ratelimited("Write to unrecognized MSR 0x%x by %s\n"
93 "Please report to x86(a)kernel.org\n",
94 reg, current->comm);
95
96 return 0;
97 }
98
99 static ssize_t msr_write(struct file *file, const char __user *buf,
100 size_t count, loff_t *ppos)
101 {
102 const u32 __user *tmp = (const u32 __user *)buf;
103 u32 data[2];
104 u32 reg = *ppos;
105 int cpu = iminor(file_inode(file));
106 int err = 0;
107 ssize_t bytes = 0;
108
109 err = security_locked_down(LOCKDOWN_MSR);
110 if (err)
111 return err;
112
113 err = filter_write(reg);
114 if (err)
115 return err;
116
117 if (count % 8)
118 return -EINVAL; /* Invalid chunk size */
119
120 for (; count; count -= 8) {
121 if (copy_from_user(&data, tmp, 8)) {
122 err = -EFAULT;
123 break;
124 }
125
126 add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
127
128 err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]);
129 if (err)
130 break;
131
132 tmp += 2;
133 bytes += 8;
134 }
135
136 return bytes ? bytes : err;
137 }
138
139 static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
140 {
141 u32 __user *uregs = (u32 __user *)arg;
142 u32 regs[8];
143 int cpu = iminor(file_inode(file));
144 int err;
145
146 switch (ioc) {
147 case X86_IOC_RDMSR_REGS:
148 if (!(file->f_mode & FMODE_READ)) {
149 err = -EBADF;
150 break;
151 }
152 if (copy_from_user(®s, uregs, sizeof(regs))) {
153 err = -EFAULT;
154 break;
155 }
156 err = rdmsr_safe_regs_on_cpu(cpu, regs);
157 if (err)
158 break;
159 if (copy_to_user(uregs, ®s, sizeof(regs)))
160 err = -EFAULT;
161 break;
162
163 case X86_IOC_WRMSR_REGS:
164 if (!(file->f_mode & FMODE_WRITE)) {
165 err = -EBADF;
166 break;
167 }
168 if (copy_from_user(®s, uregs, sizeof(regs))) {
169 err = -EFAULT;
170 break;
171 }
172 err = security_locked_down(LOCKDOWN_MSR);
173 if (err)
174 break;
175 err = wrmsr_safe_regs_on_cpu(cpu, regs);
176 if (err)
177 break;
178 if (copy_to_user(uregs, ®s, sizeof(regs)))
179 err = -EFAULT;
180 break;
181
182 default:
183 err = -ENOTTY;
184 break;
185 }
186
187 return err;
188 }
189
190 static int msr_open(struct inode *inode, struct file *file)
191 {
192 unsigned int cpu = iminor(file_inode(file));
193 struct cpuinfo_x86 *c;
194
195 if (!capable(CAP_SYS_RAWIO))
196 return -EPERM;
197
198 if (cpu >= nr_cpu_ids || !cpu_online(cpu))
199 return -ENXIO; /* No such CPU */
200
201 c = &cpu_data(cpu);
202 if (!cpu_has(c, X86_FEATURE_MSR))
203 return -EIO; /* MSR not supported */
204
205 return 0;
206 }
207
208 /*
209 * File operations we support
210 */
211 static const struct file_operations msr_fops = {
212 .owner = THIS_MODULE,
213 .llseek = no_seek_end_llseek,
214 .read = msr_read,
215 .write = msr_write,
216 .open = msr_open,
217 .unlocked_ioctl = msr_ioctl,
218 .compat_ioctl = msr_ioctl,
219 };
220
221 static int msr_device_create(unsigned int cpu)
222 {
223 struct device *dev;
224
225 dev = device_create(msr_class, NULL, MKDEV(MSR_MAJOR, cpu), NULL,
226 "msr%d", cpu);
227 return PTR_ERR_OR_ZERO(dev);
228 }
229
230 static int msr_device_destroy(unsigned int cpu)
231 {
232 device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu));
233 return 0;
234 }
235
236 static char *msr_devnode(struct device *dev, umode_t *mode)
237 {
238 return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
239 }
240
241 static int __init msr_init(void)
242 {
243 int err;
244
245 if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops))
{
246 pr_err("unable to get major %d for msr\n", MSR_MAJOR);
247 return -EBUSY;
248 }
249 msr_class = class_create(THIS_MODULE, "msr");
250 if (IS_ERR(msr_class)) {
251 err = PTR_ERR(msr_class);
252 goto out_chrdev;
253 }
254 msr_class->devnode = msr_devnode;
255
256 err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online",
257 msr_device_create, msr_device_destroy);
258 if (err < 0)
259 goto out_class;
260 cpuhp_msr_state = err;
261 return 0;
262
263 out_class:
264 class_destroy(msr_class);
265 out_chrdev:
266 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
267 return err;
268 }
269 module_init(msr_init);
270
271 static void __exit msr_exit(void)
272 {
273 cpuhp_remove_state(cpuhp_msr_state);
274 class_destroy(msr_class);
275 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
276 }
277 module_exit(msr_exit)
278
279 static int set_allow_writes(const char *val, const struct kernel_param *cp)
280 {
281 char *s = strstrip(val);
282
283 if (!strcmp(s, "on"))
284 allow_writes = MSR_WRITES_ON;
285 else if (!strcmp(s, "off"))
286 allow_writes = MSR_WRITES_OFF;
287 else
288 allow_writes = MSR_WRITES_DEFAULT;
289
290 return 0;
291 }
292
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org