Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3919806pxj; Mon, 21 Jun 2021 09:22:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPimIZYfMgEfB01sf4EPi/94xHC30BvDNs5+FT9f4a/X8vyMGKIMy5G7byJs5p3+XV0bf4 X-Received: by 2002:a17:906:fb0f:: with SMTP id lz15mr11384267ejb.545.1624292569420; Mon, 21 Jun 2021 09:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292569; cv=none; d=google.com; s=arc-20160816; b=L653hYA2ZjbsJJlX11gIuCaCuzBWkDaVz/6Dw6g54ZOOwMUYRXfGA9zQG+XsCHDLoj g+hpJt+PV2xQmMQjxJNB2AeO05Or4PvFVQNYOt7LnWnv8JM+Y7yefyXdDAzF6DKcRpLh x0a95MqBLj9B8LFHn1KISGumIPU0YBKPT4XOSUu0lmYlKi9kbi2OgfJSbkRzbVCcyLd7 07q6AntCn+3zFYNvYlpWTq1cGpeDy59Za/dbttVlEC1oEJWE5RFcmRj39pIpHzmbdee4 BHY+lIt5k7Bo1H3hW68l/cg7Vf1bpnw3u6I7qYTz3ycEGiIYsckb2lfJnn/eHzdZgJp9 otpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o6RHMjiAwfwROap+1BARITxH7oZuNGNqGBeyqDRIIqI=; b=tgBENlFVlHEd+bDLsocQZbWOnbHSRNZFi11BFy0JY7qmXhQKpilRlBCI5zOKOXvp/l h+3TdVZ55IyrkZI5gY+D19mrIuyEUkIsXNXlSFZmjbZom2C1f5Y2p9NDj2lf09bU7YNn mlUOHq+kG6ZwAWS7H20nTZ64OkM1XB6ud9zN0gxWAcfemNOX6+GcNgOLcymFJwhWB9zW USlCj/wx4NKnexl+P9l9KLu0+w0m+hXtm4MuzG/1g01DG7OWN+Uw1gpLkyfJJFMjJgxC INR5OOxpsEzQHLnr0ComMolEk6gWy72r+Hg5/5SruG2N/+CDaISM8qPoGOy9h8LBke6b e+MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qtc8RBIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si11848871eja.301.2021.06.21.09.22.27; Mon, 21 Jun 2021 09:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qtc8RBIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231689AbhFUQVM (ORCPT + 99 others); Mon, 21 Jun 2021 12:21:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:39908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbhFUQU2 (ORCPT ); Mon, 21 Jun 2021 12:20:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6960B6128A; Mon, 21 Jun 2021 16:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292293; bh=QCo9LUr1jp2cGyDlX+ktQS2q+vgJ6CS/qTUdVpASKTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qtc8RBIa7p8sjpRgBIziCEz2dtkA5Ei+wRzahP35DGb/uZtg4Uet7Sn7Yzc5GvNPm b4MCR5SLM2a5qKZFuBoaRRO+/bRbs72V0j2vlgcSESGKPhQ/86P+c+2QyEwkiZIbMP mSnPmSabqPKwyFdLJyyUPaRPWRxU1utBXtWZ0ua0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jim Mattson , syzbot , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.4 06/90] kvm: LAPIC: Restore guard to prevent illegal APIC register access Date: Mon, 21 Jun 2021 18:14:41 +0200 Message-Id: <20210621154904.367716440@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jim Mattson [ Upstream commit 218bf772bddd221489c38dde6ef8e917131161f6 ] Per the SDM, "any access that touches bytes 4 through 15 of an APIC register may cause undefined behavior and must not be executed." Worse, such an access in kvm_lapic_reg_read can result in a leak of kernel stack contents. Prior to commit 01402cf81051 ("kvm: LAPIC: write down valid APIC registers"), such an access was explicitly disallowed. Restore the guard that was removed in that commit. Fixes: 01402cf81051 ("kvm: LAPIC: write down valid APIC registers") Signed-off-by: Jim Mattson Reported-by: syzbot Message-Id: <20210602205224.3189316-1-jmattson@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/lapic.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 3f6b866c644d..eea2d6f10f59 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1332,6 +1332,9 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len, if (!apic_x2apic_mode(apic)) valid_reg_mask |= APIC_REG_MASK(APIC_ARBPRI); + if (alignment + len > 4) + return 1; + if (offset > 0x3f0 || !(valid_reg_mask & APIC_REG_MASK(offset))) return 1; -- 2.30.2