From patchwork Tue Oct 1 22:01:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Whitfield X-Patchwork-Id: 1991730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJBjb6fNJz1xtq for ; Wed, 2 Oct 2024 08:01:39 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1svkvv-0001MR-Ka; Tue, 01 Oct 2024 22:01:27 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1svkvu-0001M1-GY for kernel-team@lists.ubuntu.com; Tue, 01 Oct 2024 22:01:26 +0000 Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 52AC33F140 for ; Tue, 1 Oct 2024 22:01:26 +0000 (UTC) Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-70935871ffdso2420378a34.2 for ; Tue, 01 Oct 2024 15:01:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727820085; x=1728424885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/o8HzEkt0yzuySCkD/ExIi6cS4TYTWyxU4JZVg2MJZg=; b=foGShwK/aiuVuYtK7oYGKO6h1DwzP1yshls//n0WKSFDLARyp6RvCn7Vr5r9W0MmMX kl2KQqfPiLad3qpU3pCbAytcMxj5zapwDxQUufQ03zAWBVj7/aolb7NzJe9Jgu3LMHZc 3rP+p/hEATbOHms6Iv5xZxl0rn7PeI1blPrWQUwUwKqbzuKhC80u7+JoGjiziZtabM5s pqik1k6Es6WlKbKNFi/L7YqE1+SmiOVYRkI521Z8AUmIIsZOBVK6tbGc6cdO42lfP4s7 stxAp280ygC0K6VFKFf6KBbS5seq5Zw4suKACLJZIIM93zOyXYOBKFGjCtNy5kUQNg+f MlOg== X-Gm-Message-State: AOJu0YxrEkq/Kmrtq9NY28PQ3beXo/4ihSI+PcDiP9KDSTgD3EsHx7xJ 9lNL+ssugHA+1ISk/l9mYmpRtgQ5PKj3o+Gw8OFO/U8EabV3qsFvZU5twSReGC8odAnDvvhoh3p bXUzpM491VCbS/AwclIPqWY4OH4YkhAlZKbeAho07iTQtv/ajxDwNMGT74n3ZOVj6br4gd2/aAs kcLafRfKRuzA== X-Received: by 2002:a05:6830:3894:b0:710:e987:2659 with SMTP id 46e09a7af769-7153cded0acmr1056822a34.22.1727820085028; Tue, 01 Oct 2024 15:01:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXBKjWq4v0RG2TwdvbnMDKIqvTW2yBabbUagO9MTAChBgfeu6XU4jCIAIXgna5q6TNwljzFw== X-Received: by 2002:a05:6830:3894:b0:710:e987:2659 with SMTP id 46e09a7af769-7153cded0acmr1056797a34.22.1727820084598; Tue, 01 Oct 2024 15:01:24 -0700 (PDT) Received: from localhost ([2600:1700:3ec0:2680:a659:ad4b:1c79:ccd8]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-714fb6d2c31sm3207172a34.64.2024.10.01.15.01.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 15:01:24 -0700 (PDT) From: Ian Whitfield To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/1] KVM: s390: vsie: fix race during shadow creation Date: Tue, 1 Oct 2024 15:01:21 -0700 Message-ID: <20241001220121.32335-3-ian.whitfield@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241001220121.32335-1-ian.whitfield@canonical.com> References: <20241001220121.32335-1-ian.whitfield@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Christian Borntraeger Right now it is possible to see gmap->private being zero in kvm_s390_vsie_gmap_notifier resulting in a crash. This is due to the fact that we add gmap->private == kvm after creation: static int acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) { [...] gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); if (IS_ERR(gmap)) return PTR_ERR(gmap); gmap->private = vcpu->kvm; Let children inherit the private field of the parent. Reported-by: Marc Hartmayer Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization") Cc: Cc: David Hildenbrand Reviewed-by: Janosch Frank Reviewed-by: David Hildenbrand Reviewed-by: Claudio Imbrenda Signed-off-by: Christian Borntraeger Link: https://lore.kernel.org/r/20231220125317.4258-1-borntraeger@linux.ibm.com (backported from commit fe752331d4b361d43cfd0b89534b4b2176057c32) [ijwhitfield: adjusted context due to missing commit c3235e2dd695 ("KVM: s390: add stat counter for shadow gmap events")] CVE-2023-52639 Signed-off-by: Ian Whitfield --- arch/s390/kvm/vsie.c | 1 - arch/s390/mm/gmap.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index e07bc0d3df6f..2a53d0e3d34e 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -1206,7 +1206,6 @@ static int acquire_gmap_shadow(struct kvm_vcpu *vcpu, gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); if (IS_ERR(gmap)) return PTR_ERR(gmap); - gmap->private = vcpu->kvm; WRITE_ONCE(vsie_page->gmap, gmap); return 0; } diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index 6ea9bfe69bd2..0e662cf12029 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -1675,6 +1675,7 @@ struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, return ERR_PTR(-ENOMEM); new->mm = parent->mm; new->parent = gmap_get(parent); + new->private = parent->private; new->orig_asce = asce; new->edat_level = edat_level; new->initialized = false;