Skip to contentSkip to conversation

kvm: use PIT channel index in hpet_legacy_start mode

PATCH In review P J P 3 participants 5 messages Jan 7, 2016

Subsystems (3)
lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 kvm: use PIT channel index in hpet_legacy_start mode

From: P J P <[email protected]>

While setting the KVM PIT counters in 'kvm_pit_load_count', if 'hpet_legacy_start' is set, the function disables the timer on channel[0], instead of the respective index 'channel'. Update it to use 'channel' index parameter.

---
 arch/x86/kvm/i8254.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/i8254.c +4 -3
index 08116ff..154e936 100644
@@ -420,10 +420,11 @@ void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_s
 	u8 saved_mode;
 	if (hpet_legacy_start) {
 		/* save existing mode for later reenablement */
-		saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;
-		kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable timer */
+		saved_mode = kvm->arch.vpit->pit_state.channels[channel].mode;
+		/* disable timer */
+		kvm->arch.vpit->pit_state.channels[channel].mode = 0xff;
 		pit_load_count(kvm, channel, val);
-		kvm->arch.vpit->pit_state.channels[0].mode = saved_mode;
+		kvm->arch.vpit->pit_state.channels[channel].mode = saved_mode;
 	} else {
 		pit_load_count(kvm, channel, val);
 	}
Signature · 1 line
2.4.3
#1 lore raw
Quoted 22 lines · P J P

From: P J P <[email protected]>

While setting the KVM PIT counters in 'kvm_pit_load_count', if 'hpet_legacy_start' is set, the function disables the timer on channel[0], instead of the respective index 'channel'. Update it to use 'channel' index parameter.

---
  arch/x86/kvm/i8254.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/i8254.c +0 -1
index 08116ff..154e936 100644
@@ -420,10 +420,11 @@ void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_s
  	u8 saved_mode;
  	if (hpet_legacy_start) {
  		/* save existing mode for later reenablement */
-		saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;

arch/x86/kvm/i8254.c void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_s · line 430

Quoted 10 lines
arch/x86/kvm/i8254.c +4 -2
-		kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable timer */
+		saved_mode = kvm->arch.vpit->pit_state.channels[channel].mode;
+		/* disable timer */
+		kvm->arch.vpit->pit_state.channels[channel].mode = 0xff;
  		pit_load_count(kvm, channel, val);
-		kvm->arch.vpit->pit_state.channels[0].mode = saved_mode;
+		kvm->arch.vpit->pit_state.channels[channel].mode = saved_mode;
  	} else {
  		pit_load_count(kvm, channel, val);
  	}

Will this trigger the same issue like CVE-2015-7513 ?

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0185604c2d82c560dab2f2933a18f797e74ab5a8

Signature · 2 lines
best regards
yang
maintainer
#2 lore raw
Quoted 38 lines · Yang Zhang
Quoted 25 lines · P J P

From: P J P <[email protected]>

While setting the KVM PIT counters in 'kvm_pit_load_count', if 'hpet_legacy_start' is set, the function disables the timer on channel[0], instead of the respective index 'channel'. Update it to use 'channel' index parameter.

---
  arch/x86/kvm/i8254.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/i8254.c +0 -0
index 08116ff..154e936 100644
@@ -420,10 +420,11 @@ void kvm_pit_load_count(struct kvm *kvm, int

channel, u32 val, int hpet_legacy_s

      u8 saved_mode;
      if (hpet_legacy_start) {
          /* save existing mode for later reenablement */
arch/x86/kvm/i8254.c +0 -2
-        saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;
-        kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable

timer */

arch/x86/kvm/i8254.c

Quoted 9 lines
arch/x86/kvm/i8254.c +4 -1
+        saved_mode = kvm->arch.vpit->pit_state.channels[channel].mode;
+        /* disable timer */
+        kvm->arch.vpit->pit_state.channels[channel].mode = 0xff;
          pit_load_count(kvm, channel, val);
-        kvm->arch.vpit->pit_state.channels[0].mode = saved_mode;
+        kvm->arch.vpit->pit_state.channels[channel].mode = saved_mode;
      } else {
          pit_load_count(kvm, channel, val);
      }

Will this trigger the same issue like CVE-2015-7513 ?

Quoted 1 line

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0185604c2d82c560dab2f2933a18f797e74ab5a8

I am not sure (--verbose please :)) but the right fix is to change the caller like this:

arch/x86/kvm/i8254.c +1 -0
index 08116ff227cc..b0ea42b78ccd 100644
@@ -420,6 +420,7 @@ void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_s
 	u8 saved_mode;
 	if (hpet_legacy_start) {
 		/* save existing mode for later reenablement */
+		WARN_ON(channel != 0);
 		saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;
 		kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable timer */
 		pit_load_count(kvm, channel, val);
arch/x86/kvm/x86.c +2 -1
index 7ffc224bbe41..97592e190413 100644
@@ -3606,7 +3606,8 @@ static int kvm_vm_ioctl_set_pit2(struct kvm *kvm, struct kvm_pit_state2 *ps)
 	       sizeof(kvm->arch.vpit->pit_state.channels));
 	kvm->arch.vpit->pit_state.flags = ps->flags;
 	for (i = 0; i < 3; i++)
-		kvm_pit_load_count(kvm, i, kvm->arch.vpit->pit_state.channels[i].count, start);
+		kvm_pit_load_count(kvm, i, kvm->arch.vpit->pit_state.channels[i].count,
+				   start && i == 0);
 	mutex_unlock(&kvm->arch.vpit->pit_state.lock);
 	return 0;
 }

Thanks,

Paolo

author
#3 lore raw
+-- On Thu, 7 Jan 2016, Paolo Bonzini wrote --+
| > Will this trigger the same issue like CVE-2015-7513 ?
| > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0185604c2d82c560dab2f2933a18f797e74ab5a8
| 
| I am not sure (--verbose please :))

IIUC, it shouldn't, because pit_load_count() does

    /*
     * The largest possible initial count is 0; this is equivalent
     * to 216 for binary counting and 104 for BCD counting.
     */
    if (val == 0)
        val = 0x10000;

| but the right fix is to change the caller like this:

| diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
| @@ -420,6 +420,7 @@ void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_s
|  	u8 saved_mode;
|  	if (hpet_legacy_start) {
|  		/* save existing mode for later reenablement */
| +		WARN_ON(channel != 0);
|  		saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;
|  		kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable timer */
|  		pit_load_count(kvm, channel, val);

In that case I guess, 'pit_load_count' could be called as

+ pit_load_count(kvm, 0, val);

Thank you.
--
- P J P
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

maintainer
#4 lore raw
Quoted 28 lines · P J P
+-- On Thu, 7 Jan 2016, Paolo Bonzini wrote --+
| > Will this trigger the same issue like CVE-2015-7513 ?
| > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0185604c2d82c560dab2f2933a18f797e74ab5a8
| 
| I am not sure (--verbose please :))

IIUC, it shouldn't, because pit_load_count() does

    /*
     * The largest possible initial count is 0; this is equivalent
     * to 216 for binary counting and 104 for BCD counting.
     */
    if (val == 0)
        val = 0x10000;

| but the right fix is to change the caller like this:

| diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
| @@ -420,6 +420,7 @@ void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_s
|  	u8 saved_mode;
|  	if (hpet_legacy_start) {
|  		/* save existing mode for later reenablement */
| +		WARN_ON(channel != 0);
|  		saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;
|  		kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable timer */
|  		pit_load_count(kvm, channel, val);
Quoted 3 lines

In that case I guess, 'pit_load_count' could be called as

+ pit_load_count(kvm, 0, val);

Good idea.

Paolo

Quoted 6 lines

Thank you.
--
- P J P
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F