From patchwork Wed Apr 19 10:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13216615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19060C77B75 for ; Wed, 19 Apr 2023 10:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=6W/5AG3+nZyrBbuMhISu2T7OnUgV4DEp6BXLv1a5wW0=; b=lBUEKatdKOD5Cb +RlYMShEnJ5HL3KoIN2vuMFC4TSu/b45KCYd9x7Q/1zCPxR5TayusMov5Khr1GvhP3uARIh3s0SSz HMu9VnoBWiMjxiocgBqc0CXKa+o6pTjtZ06cZiq5PyNfZyn7xa7fgNaqaF5UdLxfTCeg+3TQzv5FQ MhO4lh8y5LfnJqe+I9sKu7XjbFsC4+AprMrVjlJYwpNMoqYIY3keu2LlVmgZSoxwHiNXTY3pgLQsV joa8g6UElr0T/Dhw27F0fewhFR6FiKLQb9x89xl7uOB4GFcjBflmLLkzuzZYJr0rcwaKAdFz9oz8y dYYgXwfTaSDJEoLOss8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pp4rR-004ryX-0v; Wed, 19 Apr 2023 10:16:25 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pp4rN-004rxX-39 for linux-arm-kernel@lists.infradead.org; Wed, 19 Apr 2023 10:16:23 +0000 Received: by mail-wm1-x32b.google.com with SMTP id gw13so16835631wmb.3 for ; Wed, 19 Apr 2023 03:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681899378; x=1684491378; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=rPcJtM/qvgD7Ydsb0412bscSrzwXXzWCh+7Eqp0cORw=; b=KXsLSpx0jI1kNU+p0EO76wj/TL7n3/j0tKh99FFz9OAsCvrhMPt4DieEOZF5akBNIL WxKlTwjfRl6wEYtN/bi14odLZeL3WllmKOxi0QPucg0x/UoRJ65VwHi+V1izPJs0kOYJ vb1dIF5ccvoTbZjWYX92NCMjHTPJ4godzoiudWhHpd7ZgaBEIzhjhFsJ5+/RRD1NXact 6wc+5AbnbJB77Khmop9CVf24OurLZxwrJjPDhViffKYAr8HP56K5V0n4aMYz0xzk4S/a YS9LNSGYyUEvDjQ/su5bQvahjjXB6Wl65VN7PgNutpgPGAUjDqcFcA2s1XehR07aMGQh VqfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681899378; x=1684491378; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rPcJtM/qvgD7Ydsb0412bscSrzwXXzWCh+7Eqp0cORw=; b=WAkXc+7HY7exBSJnBbLOrjTROMautNDcMaVlznBUAAd/mVSgAsP2aZvBGPMD3akdjP R1qwuJpwV2vRI3ZDy6zfK62g4O+hytlCfCcH4I7QmxulLNl5yfGnO7671fP5BJeCCzuw Ccje33FbUste6TGvJnflV46zbk/4lFEiugSA7HPFImL0enZo4NlB3RPMw0umlh6G+1Px xOXK+Tt0XPZ1jZzPn63AJ+jTaWv+7eI8ZoZ8erW81Yb8jvsjYztls3Tz9uWL84jLxNGi JWIcTbQj+jEzNC4UDhw0LGB/vSQKdqUROO4JKfbY+nLaiQafswguRJHQ/GM66Mik0TIt 3OXg== X-Gm-Message-State: AAQBX9fsZakXJQrt4vGpngB0zLZ+RoGoC3qLIITVIubtmd0yXAKnbsZM pMuXqoqOJFxaWe6zsJNi6/bapw== X-Google-Smtp-Source: AKy350aEHBzsMieGjP0fxml8DwagDGYBm2MsSTUbOaxuPaDLRKC+WnSJcv/TzlDiCUp8g0ECW60bKg== X-Received: by 2002:a7b:ce06:0:b0:3eb:29fe:f922 with SMTP id m6-20020a7bce06000000b003eb29fef922mr15929105wmc.29.1681899377915; Wed, 19 Apr 2023 03:16:17 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id s13-20020a7bc38d000000b003f1745c7df3sm1728394wmj.23.2023.04.19.03.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 03:16:17 -0700 (PDT) Date: Wed, 19 Apr 2023 13:16:13 +0300 From: Dan Carpenter To: Andre Przywara Cc: Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Eric Auger , Steven Price , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kernel-janitors@vger.kernel.org Subject: [PATCH v2] KVM: arm64: Fix buffer overflow in kvm_arm_set_fw_reg() Message-ID: <4efbab8c-640f-43b2-8ac6-6d68e08280fe@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230419_031622_081217_D2067651 X-CRM114-Status: GOOD ( 12.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The KVM_REG_SIZE() comes from the ioctl and it can be a power of two between 0-32768 but if it is more than sizeof(long) this will corrupt memory. Fixes: 99adb567632b ("KVM: arm/arm64: Add save/restore support for firmware workaround state") Signed-off-by: Dan Carpenter Reviewed-by: Steven Price Reviewed-by: Eric Auger Reviewed-by: Marc Zyngier --- v2: The original patch was okay but checking for != sizeof(val) is stricter and more Obviously Correct[tm]. Return -ENOENT instead of -EINVAL in case future ioctls are added which take a different size. arch/arm64/kvm/hypercalls.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 2e16fc7b31bf..7fb4df0456de 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -544,6 +544,8 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) u64 val; int wa_level; + if (KVM_REG_SIZE(reg->id) != sizeof(val)) + return -ENOENT; if (copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id))) return -EFAULT;