Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3983356pxb; Mon, 4 Oct 2021 14:24:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyb1sRXSH+pVe4r3LeNQSgODzOoQ1X0B4X3slqG4OJhaQ+7f1Ys+Gu6sUUJKbhGuTNpdbRd X-Received: by 2002:a63:1656:: with SMTP id 22mr12763854pgw.20.1633382652430; Mon, 04 Oct 2021 14:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633382652; cv=none; d=google.com; s=arc-20160816; b=dxqG94EP7zxSgLD61TJsoBNec8LZXv7vnMxT9yjieW+3HfLqE+ILlur4R1KRPC/1vH n9zJXA1rGDPR0BQyQhOJlDRrQansqO8RLKv1uxea2mTxjgzyk57uBq0st4jqTOpoDExN YIgWSIh14XujLOm9q0P1Dnv7mFtKmfRLmbxdT/jms2nMoIO+3vNFUAMrfWv1ixo471HP xCuAlddDN3ACkjE2ggBSZUbs2P0guBHEAI3YOCNKvOBkYareP753IdfhHFvTN0lB8xdc bhaI5HNc1mND0+wABfb0vz5eyEYq+hmF7hU0PdlLcaVFmghTpbgT2Z/lbX7+AvWx9fyZ AZsA== 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=h0JrVJf2g2/ysQGmfA8jsOuOkUO01bD8XZkdjBUIRms=; b=MbNKXCVmQnkIumb+qYeLLtLy1FUFLaoVyVrhsEC+nS2S93I4uBeOuvZqziO+4JjSQn B1FTRacJjPkn+oeoGmdEhBTFcRXlOO7MHGSQ3UD+bOdLPTfQw+TKEZFTO+skQVvuZVEh q4AnuT84RA2afanhPEQjQV9RRTM+sRprf+Sgezo3MTTlI29/Onmp6YofbTUq5h1iCIFu 1vJKJvAfKH/gUo9CK+d1jx/ftSuiL3zjqZ6KodB6HUKVOtSDLOdFVj2nde17evSgwEX8 aM1b9sD77QURSi84oRBgQ7wm9f16++Y/WTv28tX6XRGGNkHzquFNCrgL61k1S19cgtdB IZPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RslifDSM; 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 h3si21872854plk.427.2021.10.04.14.24.00; Mon, 04 Oct 2021 14:24:12 -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=RslifDSM; 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 S237575AbhJDNcs (ORCPT + 99 others); Mon, 4 Oct 2021 09:32:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:46660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237827AbhJDNao (ORCPT ); Mon, 4 Oct 2021 09:30:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 610B363216; Mon, 4 Oct 2021 13:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353238; bh=2FRvb1V+l4HExkvUZ8x62l9KF9jfqgK4JUZduYQLh2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RslifDSMdylJVGoh3sOgVA8dy4sbJUvOh/ggOT3fT/9opq0SZoaWlms/5KEf/S3/u IMAyZr8mldkNxO/s30dIjVbw3ib75pHpNlnFFj/Mmszcc4sOQpF3PQw29T8UJ23rnQ D/c2fZkqruScAA3hG1qUAiskUU69ETja1N6gwgg0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zelin Deng , Paolo Bonzini Subject: [PATCH 5.14 049/172] ptp: Fix ptp_kvm_getcrosststamp issue for x86 ptp_kvm Date: Mon, 4 Oct 2021 14:51:39 +0200 Message-Id: <20211004125046.576094551@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: Zelin Deng commit 773e89ab0056aaa2baa1ffd9f044551654410104 upstream. hv_clock is preallocated to have only HVC_BOOT_ARRAY_SIZE (64) elements; if the PTP_SYS_OFFSET_PRECISE ioctl is executed on vCPUs whose index is 64 of higher, retrieving the struct pvclock_vcpu_time_info pointer with "src = &hv_clock[cpu].pvti" will result in an out-of-bounds access and a wild pointer. Change it to "this_cpu_pvti()" which is guaranteed to be valid. Fixes: 95a3d4454bb1 ("Switch kvmclock data to a PER_CPU variable") Signed-off-by: Zelin Deng Cc: Message-Id: <1632892429-101194-3-git-send-email-zelin.deng@linux.alibaba.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- drivers/ptp/ptp_kvm_x86.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) --- a/drivers/ptp/ptp_kvm_x86.c +++ b/drivers/ptp/ptp_kvm_x86.c @@ -15,8 +15,6 @@ #include #include -struct pvclock_vsyscall_time_info *hv_clock; - static phys_addr_t clock_pair_gpa; static struct kvm_clock_pairing clock_pair; @@ -28,8 +26,7 @@ int kvm_arch_ptp_init(void) return -ENODEV; clock_pair_gpa = slow_virt_to_phys(&clock_pair); - hv_clock = pvclock_get_pvti_cpu0_va(); - if (!hv_clock) + if (!pvclock_get_pvti_cpu0_va()) return -ENODEV; ret = kvm_hypercall2(KVM_HC_CLOCK_PAIRING, clock_pair_gpa, @@ -64,10 +61,8 @@ int kvm_arch_ptp_get_crosststamp(u64 *cy struct pvclock_vcpu_time_info *src; unsigned int version; long ret; - int cpu; - cpu = smp_processor_id(); - src = &hv_clock[cpu].pvti; + src = this_cpu_pvti(); do { /*