From patchwork Thu Nov 2 18:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13444112 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C98621114 for ; Thu, 2 Nov 2023 18:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FOVvAT9j" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04FEC134 for ; Thu, 2 Nov 2023 11:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698948964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lX9pDYhUv0xNWCwt2hkI8FAcvsPw051Wv1MARO9LEh8=; b=FOVvAT9jGjFKOX7lJDq9F37aroIE+8WU6feEIfqXeISriC1ts5Xx3602+JtGBl6a+jpUhe wJG4UQo5iy+gzT/q86rTsO/05Qw3QKtc5uh4nqhDXNBDDUJfXHMmWuKrjD8Pwpnbbx5Ft3 eCC03cX6M/SyNxrwuNcgAINoQ27spyo= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-349-B8hRMxwYOAuLMcKn-vnp-Q-1; Thu, 02 Nov 2023 14:16:02 -0400 X-MC-Unique: B8hRMxwYOAuLMcKn-vnp-Q-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2c509f2c0c7so2559021fa.0 for ; Thu, 02 Nov 2023 11:16:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698948961; x=1699553761; 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=lX9pDYhUv0xNWCwt2hkI8FAcvsPw051Wv1MARO9LEh8=; b=o6hbkiLe9kj9OQAzegmvNPu17gj6UXdqqv6gO8KfYuNk2Bk9XUolHjRqSgGujdiZeU ZQYwlsD82ndDWf5st8G07qDfzfanyM6v77bgglOZMK1q9pq52JAKS2XYdm6iptAe0xfe C7V1E5YGA7AmVtZ+JeoZShjsSLxkMGynkRUstPSxdwZLyPSpYYiDHO9vZ+216fgY7kzY kmICl8+3jlBC9LxUtT37UAoC2Vi3MuAmFXGWqcBK76OmNUEkwmVSyAsGkSvshJyvi7dh U8+0cnTexAbRa+40jS6a8PpMdTIhy7tZEKVJltDmyyyRl+eNNTF9GPjECrnbncJ6KFSy O3yQ== X-Gm-Message-State: AOJu0YwNfygW9B2SHWB2bvbBd+8cVuJTO34xpfXbxF2qz0//aJ6AtWL+ o5fR19S72s1t7jEkon7tjDxvdCNiufCc4OVBN0namrSq/RvGpmhePcTbEkr0/4HvwA9XidmYXbX r4eyFNiIi7FwK X-Received: by 2002:a2e:b5cd:0:b0:2c0:7d6:1349 with SMTP id g13-20020a2eb5cd000000b002c007d61349mr13191948ljn.0.1698948960948; Thu, 02 Nov 2023 11:16:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEA9GFg/9wbEsQk9hiRtyKr5Sw8+tU0lzjpfffLtjFPJgequPAx/iZqfrIIRwYQeDUno1rPwQ== X-Received: by 2002:a2e:b5cd:0:b0:2c0:7d6:1349 with SMTP id g13-20020a2eb5cd000000b002c007d61349mr13191934ljn.0.1698948960612; Thu, 02 Nov 2023 11:16:00 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id m28-20020a05600c3b1c00b004076f522058sm3879929wms.0.2023.11.02.11.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:16:00 -0700 (PDT) From: Philipp Stanner To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Philipp Stanner , Dave Airlie Subject: [PATCH 1/3] arch/x86/kvm: copy user-array with overflow-check Date: Thu, 2 Nov 2023 19:15:24 +0100 Message-ID: <20231102181526.43279-2-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102181526.43279-1-pstanner@redhat.com> References: <20231102181526.43279-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cpuid.c utilizes vmemdup_user() and array_size() to copy two userspace arrays. This, currently, does not check for an overflow. Use the new wrapper vmemdup_array_user() to copy the arrays more safely. Suggested-by: Dave Airlie Signed-off-by: Philipp Stanner --- arch/x86/kvm/cpuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 773132c3bf5a..4a15b2a20f84 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -467,7 +467,7 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, return -E2BIG; if (cpuid->nent) { - e = vmemdup_user(entries, array_size(sizeof(*e), cpuid->nent)); + e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e)); if (IS_ERR(e)) return PTR_ERR(e); @@ -511,7 +511,7 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, return -E2BIG; if (cpuid->nent) { - e2 = vmemdup_user(entries, array_size(sizeof(*e2), cpuid->nent)); + e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2)); if (IS_ERR(e2)) return PTR_ERR(e2); } From patchwork Thu Nov 2 18:15:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13444113 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF2AC21117 for ; Thu, 2 Nov 2023 18:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AmKeNG6e" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17A85B9 for ; Thu, 2 Nov 2023 11:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698948964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zgG3A5hpFrp+6V7xcOap0dfvpVeqP5J5h/8swybWPW8=; b=AmKeNG6e5TGAmov2bQOQ1EysZ4KQklR/7TXeewd+jGPyLxfPHn5T9d0BEEvy/xefL6F1MB IWHk/IoFW9gAe01jfrFvoNErDm+78E+A8DJSFnAFYrp26F4FlSjI3TQIH0A/hIrRhYjZ/9 4vak1+LpLGk/nmbSVc5rqCJqFyZPiAM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-9qhIlTQfPEyVY_YdJYdQfg-1; Thu, 02 Nov 2023 14:16:03 -0400 X-MC-Unique: 9qhIlTQfPEyVY_YdJYdQfg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4083e371a18so1445655e9.0 for ; Thu, 02 Nov 2023 11:16:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698948962; x=1699553762; 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=zgG3A5hpFrp+6V7xcOap0dfvpVeqP5J5h/8swybWPW8=; b=NNGovGs48a3AByWY0VMh8u12j2K40pxY9cXoM4viN8JL73oPoWz08j2I+uYq+w3Czl vFqElz7Gx1i/KKfs8gpqatKwCchqBEc4GyfU030sv8IEXyX+hfgymM5FAX1GQNAVzjMb yM9LKDKT4DH7tMOXwUY4HlGOr6H5qC8OQu+0CdUjVTHMsB1Jzj51baTUaCSheFRP0rCY riO43MI7N2GSt0I6VSTc9uQFz44cFVknxtOVpXvl5HFnyZwojmmAlrqGrJOBh4Hb68LL dUlepYo1KT1eTE+UKlNJWWRBytlRGHI8ZRSGTvEVGNb87DW4CcdPA0+zgS8sYfoVrOr0 u97Q== X-Gm-Message-State: AOJu0YyOfjz3wo363l2+WUoRWQl8q7abMm2DXmqmgpbq+b5tELMsk4Lo IouhDgw8+iMY4KVsAUZzfoX8JFYtT3iugZzpTCOnKqsnM8XmX2tUAMroIfRk6FlOBX7MmeUtjbw qyCmkc+ikMvgu X-Received: by 2002:a05:600c:510a:b0:405:1ba2:4fcf with SMTP id o10-20020a05600c510a00b004051ba24fcfmr15629806wms.4.1698948962015; Thu, 02 Nov 2023 11:16:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjTetfCnz62A+Ip2Hdlm3nuttWd2b6W3o5YuoU7reIi83z2x4Kzw5EwS3QOFs2J4hJ+0CIUg== X-Received: by 2002:a05:600c:510a:b0:405:1ba2:4fcf with SMTP id o10-20020a05600c510a00b004051ba24fcfmr15629783wms.4.1698948961745; Thu, 02 Nov 2023 11:16:01 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id m28-20020a05600c3b1c00b004076f522058sm3879929wms.0.2023.11.02.11.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:16:01 -0700 (PDT) From: Philipp Stanner To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Philipp Stanner , Dave Airlie Subject: [PATCH 2/3] arch/s390/kvm: copy userspace-array safely Date: Thu, 2 Nov 2023 19:15:25 +0100 Message-ID: <20231102181526.43279-3-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102181526.43279-1-pstanner@redhat.com> References: <20231102181526.43279-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 guestdbg.c utilizes memdup_user() to copy a userspace array. This, currently, does not check for an overflow. Use the new wrapper memdup_array_user() to copy the array more safely. Suggested-by: Dave Airlie Signed-off-by: Philipp Stanner Acked-by: Claudio Imbrenda --- arch/s390/kvm/guestdbg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/s390/kvm/guestdbg.c b/arch/s390/kvm/guestdbg.c index 3765c4223bf9..80879fc73c90 100644 --- a/arch/s390/kvm/guestdbg.c +++ b/arch/s390/kvm/guestdbg.c @@ -213,8 +213,8 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, else if (dbg->arch.nr_hw_bp > MAX_BP_COUNT) return -EINVAL; - bp_data = memdup_user(dbg->arch.hw_bp, - sizeof(*bp_data) * dbg->arch.nr_hw_bp); + bp_data = memdup_array_user(dbg->arch.hw_bp, dbg->arch.nr_hw_bp, + sizeof(*bp_data)); if (IS_ERR(bp_data)) return PTR_ERR(bp_data); From patchwork Thu Nov 2 18:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13444114 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63E6F2136A for ; Thu, 2 Nov 2023 18:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BEj5L1+y" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DA2136 for ; Thu, 2 Nov 2023 11:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698948970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yH09Py8IYRdWEq70yMXJ3wDczRklXyABpCu4Oku+uko=; b=BEj5L1+yDbpj8VEFhM26+acInhu79zBTNL2rKWITBLn4Lt0sL9E8ponVmTuVq2m/tm7amL zzA8BmqVz/H1GmF3YVyk4kvUhLjIj1W9l7kPNbB/Gf58732MoZSCiJ4a0m7XI9d1+h9qPt Ywwbm5i+HuywuFYtii6DfeYzlw/GT1w= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-2kzVPuGuP8q6yd_hYba37A-1; Thu, 02 Nov 2023 14:16:04 -0400 X-MC-Unique: 2kzVPuGuP8q6yd_hYba37A-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2c3e3672dc8so2089161fa.1 for ; Thu, 02 Nov 2023 11:16:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698948963; x=1699553763; 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=yH09Py8IYRdWEq70yMXJ3wDczRklXyABpCu4Oku+uko=; b=u2VbuiCk2t5N4M6A/XkbOGfJujHmDbmzjMhCeiA2TKzs+nZvrWVFXnvGKKxgUL/40p JmtK7dBZJl9OgL6U/6wzdZ2DOpCOIVdYN6r0YbG4IvIUFo5UaDwt5ltZNBmsCWyyn1Uy 9hRfaEG01odu3iHOsQ/ajnbq1+zgzxzLYhzpA+spUQhOhUBBedzEF+vt959pVzNhJ/mq QZXwt+G3WdseNMxTLASU+G32VlUVhyVIk9lCcmdWNFTfNrWTeTidPFV3QzLjShY+RHEG emy/eANzJTZKk5f+vLcb/dtJG8rQ4kKXEP8J7NaWE2/rIyTggjmH0uFqM6jUGGN0XFM3 WyuQ== X-Gm-Message-State: AOJu0YyLghpNOjOk2iL78JuAeousevFhwXl6f1DWxYSXEPH31ENxsXYP 4XQeU4uaQy5awYCQrPiNmDSLEtKN4wPBzevZkFz8jYa8u0c5MyW/jT6/7hFf23cqJIFQl3RNQ2A izxmlp9oVn9GC X-Received: by 2002:a2e:9695:0:b0:2c4:ff24:b02e with SMTP id q21-20020a2e9695000000b002c4ff24b02emr14483920lji.3.1698948963402; Thu, 02 Nov 2023 11:16:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFS1zGZUHtg3KOcze+sfSekgUGd8coQqnik/gqhe4Qn0cg6IP3P+fkjw/XDjmt/1fT6T4eXsA== X-Received: by 2002:a2e:9695:0:b0:2c4:ff24:b02e with SMTP id q21-20020a2e9695000000b002c4ff24b02emr14483906lji.3.1698948963067; Thu, 02 Nov 2023 11:16:03 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c5:d600:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id m28-20020a05600c3b1c00b004076f522058sm3879929wms.0.2023.11.02.11.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:16:02 -0700 (PDT) From: Philipp Stanner To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Philipp Stanner , Dave Airlie Subject: [PATCH 3/3] virt/kvm: copy userspace-array safely Date: Thu, 2 Nov 2023 19:15:26 +0100 Message-ID: <20231102181526.43279-4-pstanner@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102181526.43279-1-pstanner@redhat.com> References: <20231102181526.43279-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 kvm_main.c utilizes vmemdup_user() and array_size() to copy a userspace array. Currently, this does not check for an overflow. Use the new wrapper vmemdup_array_user() to copy the array more safely. Suggested-by: Dave Airlie Signed-off-by: Philipp Stanner --- virt/kvm/kvm_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 486800a7024b..2a2f409c2a7d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4932,9 +4932,8 @@ static long kvm_vm_ioctl(struct file *filp, goto out; if (routing.nr) { urouting = argp; - entries = vmemdup_user(urouting->entries, - array_size(sizeof(*entries), - routing.nr)); + entries = vmemdup_array_user(urouting->entries, + routing.nr, sizeof(*entries)); if (IS_ERR(entries)) { r = PTR_ERR(entries); goto out;