From patchwork Wed Jun 5 22:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13687588 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 928673B1AB for ; Wed, 5 Jun 2024 22:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717625126; cv=none; b=Iu0KTnoesDD3BGlrkEBB8CKG10B/pM8DV3oMGsZShO8Np0FaX9ehvyHOZq/18WH5WY7k7RcL4QQdcFyVObFWXQmR5x5ITjPUmy2g4NlzPJ6J0WhvgSrQeQ2BhjmfI25cBKXoSyAAJbJdasVf/wpJYkTP8ztI+GSW2mNeDh3Xs2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717625126; c=relaxed/simple; bh=QJjnj0ss24plSTNwTQeT5jX+/7TkIkcPqBKh3DM9100=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J/0/rRLWbtts9UvTS/U8v9IJrC9WovN45VKrhr6tyOBBROiblPtTtTdrP7Ue8ifsAmxstCH6js8fxp39FyJx/5QgHEROXCNeoYX5TdTpwBpQpjmJ7uKJM7iun6uDm2/I8tUz53H2QuiTsuSjWeVgVhggJhFwhBSWuSQtTkp/4OM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=grsecurity.net; spf=pass smtp.mailfrom=opensrcsec.com; dkim=pass (2048-bit key) header.d=grsecurity.net header.i=@grsecurity.net header.b=jbDQNcSI; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=grsecurity.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensrcsec.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=grsecurity.net header.i=@grsecurity.net header.b="jbDQNcSI" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a63359aaacaso41605966b.1 for ; Wed, 05 Jun 2024 15:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1717625123; x=1718229923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J4/tUZqMJ9fVTqi7O5TJG840u6xF9S+kTH++Xf66rKI=; b=jbDQNcSIx6C7T44c6Z3ISZOe+4WgasE4/KUrL2Qagfu0OoFxrqFMV2zSfkMv/nC7wA 2CepTzJ9GdQeMw0WwgJjtyztxSBe5FxozzsYHq4HZPL106QYBj9glne1bQ7g+C/mP5p1 /LmGqvPQRYnT6ymQPYLrtEJQsgild0QwkluPPrEUVHQz7WJtCthbQsFs1xBdwm1Rvm4A ocDTeMSYQ2w0cwit1YQolAylLLKmdNsk7v2Iu1MH9CHI/exHRRZfu6KercnE/ONOVZ9K auPAP7dr9Lfwu983Wozz+Xla6tQJRCadO3DDXcbQyDjW8q2OWeQUag+wiUrBwyFBf9Ru p1kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717625123; x=1718229923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J4/tUZqMJ9fVTqi7O5TJG840u6xF9S+kTH++Xf66rKI=; b=kz7SW1U1kVdjmAdeuxMK6XLKMgbXTRX3DP3E+Q8lty/WsTLeox5/MLH3zU6lHwe+RJ wt8J38FUPCHoCc8Hw/w8CRDYy29ztKR+X5xzWpOsrSGxRDBJ/b+9xTwaWy2uUNclDtKA DX8wvvjH/dEnHb+AWjn+lcxp/aqcJiPB+ZId/6lJ2DJBn4k290RVWLhI+rk28/AB3cgi bBll9aK8HlIW+fTDjAMt7ppGJTxFWTAKrpAUAssRGY2/3c//ZLf/H9V+7VK2DLH3kiDj uq3zSPWWrTtBp/77bK7EkpNYoezc2rRDQgKqKdj3AjFlN06m8+1fftPPuEvN0E6+KMfZ wV2w== X-Gm-Message-State: AOJu0YwLi0vEoGf9/o7JeKFDHh5fQMOxWWyHjj1+p7wEuNb2gEIh52fA 4VP5qNxwsVoftWN4SDm8O1mRYPqoHj7rBkA7D8OwKt6dJK2e7Moapm5K3JjDAWE= X-Google-Smtp-Source: AGHT+IFYtL9999L+qVZxkiU7xp60uw3FS6PYPNhCQJ3zIbReDM6+/5bPb4JGdNO9mTbWIMldgcyjiw== X-Received: by 2002:a17:906:c198:b0:a63:582b:8ac1 with SMTP id a640c23a62f3a-a699face692mr255463366b.20.1717625122583; Wed, 05 Jun 2024 15:05:22 -0700 (PDT) Received: from bell.fritz.box (p200300f6af09bc00454dac98c3a8ddbc.dip0.t-ipconnect.de. [2003:f6:af09:bc00:454d:ac98:c3a8:ddbc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68f56506dcsm574559866b.57.2024.06.05.15.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 15:05:22 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, Mathias Krause , Emese Revfy , PaX Team Subject: [PATCH 1/2] KVM: Reject overly excessive IDs in KVM_CREATE_VCPU Date: Thu, 6 Jun 2024 00:05:03 +0200 Message-Id: <20240605220504.2941958-2-minipli@grsecurity.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240605220504.2941958-1-minipli@grsecurity.net> References: <20240605220504.2941958-1-minipli@grsecurity.net> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If, on a 64 bit system, a vCPU ID is provided that has the upper 32 bits set to a non-zero value, it may get accepted if the truncated to 32 bits integer value is below KVM_MAX_VCPU_IDS and 'max_vcpus'. This feels very wrong and triggered the reporting logic of PaX's SIZE_OVERFLOW plugin. Instead of silently truncating and accepting such values, pass the full value to kvm_vm_ioctl_create_vcpu() and make the existing limit checks return an error. Even if this is a userland ABI breaking change, no sane userland could have ever relied on that behaviour. Reported-by: PaX's SIZE_OVERFLOW plugin running on grsecurity's syzkaller Fixes: 6aa8b732ca01 ("[PATCH] kvm: userspace interface") Cc: Emese Revfy Cc: PaX Team Signed-off-by: Mathias Krause --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 14841acb8b95..9f18fc42f018 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4200,7 +4200,7 @@ static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) /* * Creates some virtual cpus. Good luck creating more than one. */ -static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) +static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id) { int r; struct kvm_vcpu *vcpu; From patchwork Wed Jun 5 22:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13687589 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A0C315EFA3 for ; Wed, 5 Jun 2024 22:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717625127; cv=none; b=MT3HCAqdisErdUk9DGFAVOohljZedGuV267tjYk1lRJ+FqPnHPck3M7Jy/BVZ/aGEhj8EtE9GT97w+/VWcqqrR4g2+2UsbOGmdnDA0IqW+eguMfzITASUTAFZ8D/YALw+UdNFz4tvlvfFysS2UizXVMPIaPye3hiHCog0u2TUOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717625127; c=relaxed/simple; bh=Mef8+WrFLjcRWTeyr7/n9NEG+tIXc2iTFCcmhv9M4po=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jgz/YqWm52+Qj13rGQbH384iwtuxzFPuinEJ5EsiiwoJn5BL7UaEz2z+kWRS2bjnAzogwvmK2NkR5/Tn8TJ5O463Gvnxks/2gFEpmoklp3Ywf1pDYv3iAhWOt2zBG3RslG6q1vVxWPpKH1BjVeCZBIT0ZPypTdZhpLlQ2eR9LMI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=grsecurity.net; spf=pass smtp.mailfrom=opensrcsec.com; dkim=pass (2048-bit key) header.d=grsecurity.net header.i=@grsecurity.net header.b=qOluVNgZ; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=grsecurity.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensrcsec.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=grsecurity.net header.i=@grsecurity.net header.b="qOluVNgZ" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a69607c6ccaso27603066b.2 for ; Wed, 05 Jun 2024 15:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1717625123; x=1718229923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rZbb2eMSSDdlpeUuW/bDuyvE9odB04iaefVgLAtvy4k=; b=qOluVNgZO1ISt6EK0ioj4NZr8XP/NGCehaRcJ+hHVHMHnN4EdUI4OeLvcaj/xhF+t4 CODd/DcGwb8rqoAuggunUbh5r6IGE3dirx3lTfRIWY0uFvFARngrZVX0y8eT+1O9QHuW KSkWLwiTLYgLdkUjx8VtjyP35htPRfaWYRiQSgtHgr3PY/gPTy2os7rx7xp0ZxQwbXJ1 9VBsNR23c11TjxdXPREjWDX+usOSkoOdxh/wghq7nzlM582WU9AsjFFBqjXg64ngcHZ/ YVwI0n22K0AfIDOjePHsxPmVb9t3BeAzfVXrZMpnBTpkqa8AYfCQDvfRRzMBPwGa7MFd kjVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717625123; x=1718229923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rZbb2eMSSDdlpeUuW/bDuyvE9odB04iaefVgLAtvy4k=; b=BSM/iWpl2bJryYQf5mlUJVG6IfarkcoiXUo+mnRmYat16mGhZhE2avg7lf/ehVTVHd qCn2uFWEw/0bOLZeVt84Xjxqz8uKjZMojdpDHjo2rwLkhX7U7DFnOnjAax80IdxpNa6A 5XPik+OITEqEWsFwnjm2yXNCUfjvQ/YvB0KGe47/0FA42h9fKyelHPPAgCPZMkV3rNar EW0LxtxkUkrmVV9JuRzKpPh/v+bG6TSGrBiU4wwNiCBPETQ4havtO7tHxQ+6sea4wfWc zOIdmd/hawtvW7YtRewslHW8QNvNycPvLcy7wbLGKu0Vm6bT5a0IIaxOpalWfXMYAmLS C3sg== X-Gm-Message-State: AOJu0Yw41pmR3H8/khg5FdPURuOgxaCGuLtoo7eXidGLtqRyhvxZdvof cCD/UcYFiH7Q/rS3IgKdka+6cGq4MsG28A6VzTKOr2PsvX7QSV9DoCtD6iWIZIx0i3k5OsWdVmm g X-Google-Smtp-Source: AGHT+IHcHHksoYEVtrbUnzuD3YgLEAr72AoaYN19YTmIlctLW8qHnC7Y7nZZs4qdHveKdmp5CE6EeA== X-Received: by 2002:a17:907:75c5:b0:a68:c0b8:ada9 with SMTP id a640c23a62f3a-a69a028ebdcmr212013266b.76.1717625123413; Wed, 05 Jun 2024 15:05:23 -0700 (PDT) Received: from bell.fritz.box (p200300f6af09bc00454dac98c3a8ddbc.dip0.t-ipconnect.de. [2003:f6:af09:bc00:454d:ac98:c3a8:ddbc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68f56506dcsm574559866b.57.2024.06.05.15.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 15:05:23 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, Mathias Krause Subject: [PATCH 2/2] KVM: selftests: Test vCPU IDs above 2^32 Date: Thu, 6 Jun 2024 00:05:04 +0200 Message-Id: <20240605220504.2941958-3-minipli@grsecurity.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240605220504.2941958-1-minipli@grsecurity.net> References: <20240605220504.2941958-1-minipli@grsecurity.net> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The KVM_CREATE_VCPU ioctl ABI had an implicit integer truncation bug, allowing 2^32 aliases for a vCPU ID by setting the upper 32 bits of a 64 bit ioctl() argument. Verify this no longer works and gets rejected with an error. Signed-off-by: Mathias Krause --- .../selftests/kvm/x86_64/max_vcpuid_cap_test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c b/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c index 3cc4b86832fe..92cb2f4aef6d 100644 --- a/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c +++ b/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c @@ -35,10 +35,19 @@ int main(int argc, char *argv[]) TEST_ASSERT(ret < 0, "Setting KVM_CAP_MAX_VCPU_ID multiple times should fail"); - /* Create vCPU with id beyond KVM_CAP_MAX_VCPU_ID cap*/ + /* Create vCPU with id beyond KVM_CAP_MAX_VCPU_ID cap */ ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)MAX_VCPU_ID); TEST_ASSERT(ret < 0, "Creating vCPU with ID > MAX_VCPU_ID should fail"); + /* Create vCPU with id beyond UINT_MAX */ + ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)(1L << 32)); + TEST_ASSERT(ret < 0, "Creating vCPU with ID > UINT_MAX should fail"); + + /* Create vCPU with id within bounds */ + ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)0); + TEST_ASSERT(ret >= 0, "Creating vCPU with ID 0 should succeed"); + + close(ret); kvm_vm_free(vm); return 0; }