Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3726692pxj; Mon, 21 Jun 2021 05:20:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqshx8+duZ167hO/ts6qcup6+wvRmLK930zIzSIRcarVTiqT7swBELJj2cRFeIqaj5slQ2 X-Received: by 2002:a92:7303:: with SMTP id o3mr18035590ilc.203.1624278015800; Mon, 21 Jun 2021 05:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624278015; cv=none; d=google.com; s=arc-20160816; b=Jy1RQ96UQ4Weulr1XXvbfMkkxBul/S5Pf+U9oiX27GYXBj7PGO8uZRbqMgd5FBt8bR 0+IfXZyqL+PLCUOl8xxbWFnMvyp6vFTgwFUDEO8V+twHbKxlRjYVJhomW4VKBeREazRa uzG3YyEJp0/G+SC3sk8+OTQdWwzQcuWim/f942r0TRdOucQ4EXJhxKjAx2dL0Edpg6Kz P5AUBd/DzrOVtEIeOxgi/t2rLdbgPNML4sdPmiFSRrYnjxWsaKkYtQVA0lCfeDrFJKGi Hbj2wJXzwG+gVH/ODOgLJsKtwqtbveqdB8gDB/XppQhJBOh/dc+H7NffvdQEd2g1BjNM 1yrg== 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 :message-id:date:subject:to:from:dkim-signature; bh=uZntDKbSLD8RTnNrN+qTlHrQxiWvindPPJsg1DA4mrw=; b=gWjqlFrd9rzm452K/V+8rBz9Mh3wzUvl+N4MQDqlSZuXgom+SSKPaMlpGbKRw3xFKu lNMqwBPmYPSsj/eU8sXp4onWMFL7uTXrjBmkjxMBK04ltxSQwiLvsn3oaWDWuLGk728Q DP8h+5QAtxR8N3batWHl+RoyKLmZJPH7uaejT/SATatVhDEQjOvPz812vS+8CT2vT5QX ezepEqfsVHDqRmrg9AH2PkjbRZI4oW/C7jUSskIqb0A9/oVZ7szfzqja36wvp4FWlEik FQwwDaA9d6J5AzeG0jgI4qffxC4igAhmxbGq0Q6Zs16aWGFH8Jgh6hCPn8zrHIkT4X5h YbPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bvm0VKfA; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t18si9950527jan.32.2021.06.21.05.20.02; Mon, 21 Jun 2021 05:20:15 -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=@redhat.com header.s=mimecast20190719 header.b=Bvm0VKfA; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbhFUMVG (ORCPT + 99 others); Mon, 21 Jun 2021 08:21:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52099 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbhFUMVG (ORCPT ); Mon, 21 Jun 2021 08:21:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624277932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uZntDKbSLD8RTnNrN+qTlHrQxiWvindPPJsg1DA4mrw=; b=Bvm0VKfA3XOGfeJFtxWJA1ZXkk2CZtQKHvBcHUlDXBXU5EntgBjWL9+DJtcfDEdOPqGQD7 o0obBotcjTPMxpMVlf/2aSoPLyEzbBHqpsdmrKhFUhbkWBG1KjPwfptE48Nf9+xXTdJHaw LXU+zrDjb8FpaPybRmWXgjN0mj0TWY8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-HHOQSb8_PvyMpJYi2nIVVw-1; Mon, 21 Jun 2021 08:18:48 -0400 X-MC-Unique: HHOQSb8_PvyMpJYi2nIVVw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 734431084F56; Mon, 21 Jun 2021 12:18:47 +0000 (UTC) Received: from laptop.redhat.com (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF7295D9F0; Mon, 21 Jun 2021 12:18:42 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stable@vger.kernel.org, maz@kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH] KVM: arm/arm64: Fix KVM_VGIC_V3_ADDR_TYPE_REDIST read Date: Mon, 21 Jun 2021 14:18:39 +0200 Message-Id: <20210621121839.792649-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When reading the base address of the a REDIST region through KVM_VGIC_V3_ADDR_TYPE_REDIST we expect the redistributor region list to be populated with a single element. However list_first_entry() expects the list to be non empty. Instead we should use list_first_entry_or_null which effectively returns NULL if the list is empty. Fixes: dbd9733ab674 ("KVM: arm/arm64: Replace the single rdist region by a list") Cc: # v4.19 Signed-off-by: Eric Auger Reported-by: Gavin Shan Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20210412150034.29185-1-eric.auger@redhat.com --- virt/kvm/arm/vgic/vgic-kvm-device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-kvm-device.c b/virt/kvm/arm/vgic/vgic-kvm-device.c index 6ada2432e37c..71d92096776e 100644 --- a/virt/kvm/arm/vgic/vgic-kvm-device.c +++ b/virt/kvm/arm/vgic/vgic-kvm-device.c @@ -95,8 +95,8 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) r = vgic_v3_set_redist_base(kvm, 0, *addr, 0); goto out; } - rdreg = list_first_entry(&vgic->rd_regions, - struct vgic_redist_region, list); + rdreg = list_first_entry_or_null(&vgic->rd_regions, + struct vgic_redist_region, list); if (!rdreg) addr_ptr = &undef_value; else -- 2.26.3