From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77494C433FE for ; Wed, 1 Jun 2022 08:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350807AbiFAIcB (ORCPT ); Wed, 1 Jun 2022 04:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245286AbiFAIb4 (ORCPT ); Wed, 1 Jun 2022 04:31:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 269712E095 for ; Wed, 1 Jun 2022 01:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654072313; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BRjRy4QuDv/Sqz+aOic6CcbjAuVweriyEvX/LgyeBJs=; b=IiM7frZFMjNnG0Z4up9XPhLOcPSVGzVYxYF2rqi52C3KIn47hRbrAn1VV5XKXOTQyGqvOh ASzp1IOFtoB/Ai9FTLkanTT5F2WmLIBht0KTRZmIezb803EG7nDhYYkasM+1ayRDfyZHos RwjsC0RnDifvOv0Nna1khWGzIdJiEVs= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-W_8DToH0M2qWv-1J-ixDYw-1; Wed, 01 Jun 2022 04:31:52 -0400 X-MC-Unique: W_8DToH0M2qWv-1J-ixDYw-1 Received: by mail-ed1-f69.google.com with SMTP id y13-20020a056402358d00b0042dfb820070so501414edc.6 for ; Wed, 01 Jun 2022 01:31:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=BRjRy4QuDv/Sqz+aOic6CcbjAuVweriyEvX/LgyeBJs=; b=LR9VA9wzEzVB2Lo62WnpYDu1i2cdg3ZemlK/rOGt+RsaqfspGbOmsF/UzFIMHCvpNv 0FavI3vmis5PnUdfaBqmFLItKcOVNJjt94oOEGv6qfg/Ooe0LtQCo6Gdvjk5ciRr/62c cS7RIDqkkWGWKIDiqmhGgBSwR01wFWJwiH+m4gvv0vPaMtyHc4kQx+0XRD/XetCKR30I u/FgiLtDogGYK+onktJZbBHQ2j+dnnQUSWDtuiUoeoKZFszvszwp51Rumsq5zoqYk+Q8 +2UmxfXr2wfFZzQ4WwGjyhc1iACn2Y4+d9LcYHkm5Cn7HksfUp7k8Bq2oqm3fy7TuYZk hs6g== X-Gm-Message-State: AOAM532A0AXjbeLaAJjsGsIB8JixAokP/GcQJ/e1oput9QxezGwRm/d5 XugT22Hzc3WZWsH4FG3Hv35ylgN2D2jxAI3z1p/7aukD1hbETEwY7cXe/4EkVE/QhB83hkQcmS8 649qGeiXsOmzmMu9v/cASoFGF X-Received: by 2002:a17:907:3e84:b0:6fe:8c5f:d552 with SMTP id hs4-20020a1709073e8400b006fe8c5fd552mr55954427ejc.710.1654072311199; Wed, 01 Jun 2022 01:31:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9DVJ6FqBpWGxY5tywdmZKsQoJj4ojxDb7NQ24EnoFYJieuekNxE7gt4GgF856Cxw6TXTg4g== X-Received: by 2002:a17:907:3e84:b0:6fe:8c5f:d552 with SMTP id hs4-20020a1709073e8400b006fe8c5fd552mr55954411ejc.710.1654072310968; Wed, 01 Jun 2022 01:31:50 -0700 (PDT) Received: from fedora (nat-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id 4-20020a170906310400b00705976bcd01sm415340ejx.206.2022.06.01.01.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 01:31:50 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , Robert Dinse , Paolo Bonzini Subject: Re: [PATCH v2 7/8] KVM: x86: Bug the VM if the emulator generates a bogus exception vector In-Reply-To: <20220526210817.3428868-8-seanjc@google.com> References: <20220526210817.3428868-1-seanjc@google.com> <20220526210817.3428868-8-seanjc@google.com> Date: Wed, 01 Jun 2022 10:31:49 +0200 Message-ID: <87leugokcq.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sean Christopherson writes: > Bug the VM if KVM's emulator attempts to inject a bogus exception vector. > The guest is likely doomed even if KVM continues on, and propagating a > bad vector to the rest of KVM runs the risk of breaking other assumptions > in KVM and thus triggering a more egregious bug. > > All existing users of emulate_exception() have hardcoded vector numbers > (__load_segment_descriptor() uses a few different vectors, but they're > all hardcoded), and future users are likely to follow suit, i.e. the > change to emulate_exception() is a glorified nop. > > As for the ctxt->exception.vector check in x86_emulate_insn(), the few > known times the WARN has been triggered in the past is when the field was > not set when synthesizing a fault, i.e. for all intents and purposes the > check protects against consumption of uninitialized data. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/emulate.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 70a8e0cd9fdc..2aa17462a9ac 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -624,7 +624,9 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt, int seg) > static int emulate_exception(struct x86_emulate_ctxt *ctxt, int vec, > u32 error, bool valid) > { > - WARN_ON(vec > 0x1f); > + if (KVM_EMULATOR_BUG_ON(vec > 0x1f, ctxt)) > + return X86EMUL_UNHANDLEABLE; > + > ctxt->exception.vector = vec; > ctxt->exception.error_code = error; > ctxt->exception.error_code_valid = valid; > @@ -5728,7 +5730,8 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt) > > done: > if (rc == X86EMUL_PROPAGATE_FAULT) { > - WARN_ON(ctxt->exception.vector > 0x1f); > + if (KVM_EMULATOR_BUG_ON(ctxt->exception.vector > 0x1f, ctxt)) > + return EMULATION_FAILED; > ctxt->have_exception = true; > } > if (rc == X86EMUL_INTERCEPTED) Reviewed-by: Vitaly Kuznetsov -- Vitaly