From: Tim Wiederhake <twiederh@redhat.com>
To: "Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
"Ingo Molnar" <mingo@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
x86@kernel.org
Cc: Tim Wiederhake <twiederh@redhat.com>
Subject: [PATCH 1/2] x86/msr: Read MSRs individually
Date: Tue, 23 May 2023 21:49:48 +0200 [thread overview]
Message-ID: <20230523194949.96149-1-twiederh@redhat.com> (raw)
Reading from /dev/cpu/*/msr with buffer size > 8 would read the data
of the same msr repeatedly instead of the data for consecutive msrs,
as one might expect.
Solve by restricting MSR reads to one per call.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
---
arch/x86/kernel/msr.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index 7bb17d37db01..058f2b67d0c7 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -58,24 +58,17 @@ static ssize_t msr_read(struct file *file, char __user *buf,
u32 reg = *ppos;
int cpu = iminor(file_inode(file));
int err = 0;
- ssize_t bytes = 0;
- if (count % 8)
+ if (count < 8)
return -EINVAL; /* Invalid chunk size */
- for (; count; count -= 8) {
- err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]);
- if (err)
- break;
- if (copy_to_user(tmp, &data, 8)) {
- err = -EFAULT;
- break;
- }
- tmp += 2;
- bytes += 8;
- }
+ err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]);
+ if (err)
+ return err;
+ if (copy_to_user(tmp, &data, 8))
+ return -EFAULT;
- return bytes ? bytes : err;
+ return 8;
}
static int filter_write(u32 reg)
--
2.39.2
next reply other threads:[~2023-05-23 19:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 19:49 Tim Wiederhake [this message]
2023-05-23 19:49 ` [PATCH 2/2] x86/msr: Allow unprivileged read access to some MSRs Tim Wiederhake
2023-05-23 20:31 ` H. Peter Anvin
2023-05-30 10:23 ` [PATCH v2] " Tim Wiederhake
2023-05-30 16:56 ` Jim Mattson
2023-05-30 17:19 ` Dave Hansen
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=20230523194949.96149-1-twiederh@redhat.com \
--to=twiederh@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@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
all inboxes | Powered by JetHome®