lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <51bcdd72-467c-8afb-94cb-fd756b3d63a7@users.sourceforge.net>
Date:   Fri, 20 Jan 2017 19:19:46 +0100
From:   SF Markus Elfring <elfring@...rs.sourceforge.net>
To:     kvm@...r.kernel.org, kvm-ppc@...r.kernel.org,
        linuxppc-dev@...ts.ozlabs.org, Alexander Graf <agraf@...e.com>,
        Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        Michael Ellerman <mpe@...erman.id.au>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Radim Krčmář <rkrcmar@...hat.com>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        kernel-janitors@...r.kernel.org
Subject: [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable
 "err" in kvm_htab_write()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Thu, 19 Jan 2017 22:45:56 +0100

* A local variable was set to an error code in five cases
  before a concrete error situation was detected.
  Thus move the corresponding assignments into
  if branches to indicate a software failure there.

  This issue was detected by using the Coccinelle software.

* Delete two zero assignments which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index b795dd1ac2ef..dc34729e4ad0 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -1399,22 +1399,23 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 
 	err = 0;
 	for (nb = 0; nb + sizeof(hdr) <= count; ) {
-		err = -EFAULT;
-		if (__copy_from_user(&hdr, buf, sizeof(hdr)))
+		if (__copy_from_user(&hdr, buf, sizeof(hdr))) {
+			err = -EFAULT;
 			break;
+		}
 
-		err = 0;
 		if (nb + hdr.n_valid * HPTE_SIZE > count)
 			break;
 
 		nb += sizeof(hdr);
 		buf += sizeof(hdr);
 
-		err = -EINVAL;
 		i = hdr.index;
 		if (i >= kvm->arch.hpt_npte ||
-		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
+		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) {
+			err = -EINVAL;
 			break;
+		}
 
 		hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
 		lbuf = (unsigned long __user *)buf;
@@ -1422,26 +1423,28 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 			__be64 hpte_v;
 			__be64 hpte_r;
 
-			err = -EFAULT;
 			if (__get_user(hpte_v, lbuf) ||
-			    __get_user(hpte_r, lbuf + 1))
+			    __get_user(hpte_r, lbuf + 1)) {
+				err = -EFAULT;
 				goto out;
+			}
 			v = be64_to_cpu(hpte_v);
 			r = be64_to_cpu(hpte_r);
-			err = -EINVAL;
-			if (!(v & HPTE_V_VALID))
+			if (!(v & HPTE_V_VALID)) {
+				err = -EINVAL;
 				goto out;
+			}
 			lbuf += 2;
 			nb += HPTE_SIZE;
 
 			if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT))
 				kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
-			err = -EIO;
 			ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
 							 tmp);
 			if (ret != H_SUCCESS) {
 				pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
 				       "r=%lx\n", ret, i, v, r);
+				err = -EIO;
 				goto out;
 			}
 			if (!hpte_setup && is_vrma_hpte(v)) {
@@ -1465,7 +1468,6 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 			++i;
 			hptp += 2;
 		}
-		err = 0;
 	}
 
  out:
-- 
2.11.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ