Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp650449pxb; Thu, 26 Aug 2021 11:06:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsootm7Rd0yaHlHiB0mwHdLoR5Vqxmnt8buWJlSrq6zhZdTp98rhCD3f1gJ77jC3YbQ5q/ X-Received: by 2002:a17:906:e291:: with SMTP id gg17mr5693311ejb.477.1630001210870; Thu, 26 Aug 2021 11:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630001210; cv=none; d=google.com; s=arc-20160816; b=cugKcscg2IR0tiBjaYAoyU5RF5/k64glmdxt6h0bd3o8Rg3W9fLvnS74euB1KPSnoX XTdZb6hmQd+Fe1HcAfXRX1XFseH9nwO3PAco7KnC+fbuxoQfbbhRwEijbv1MUnaAtJSw tUA/WWmTWQjca8Pbb4997229SAMv7NhO4zniC5iJN59YmtjiFvU6UcVzkOsal1DGFgrB ECwwki5+4AC5cD8K+D6ZggJQCBdIgL9tNIpkNUBZ99kQX+5YxYKnx2wFPSh8CUpJb699 gwIl27RBRu5gWN1iV7qZ2AnYk76FIr5Uxpxkww2FQghj7ksD6/0WvDIbttZqmupBB0mn cF1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QgZbnxVtGJ1vU/xYWeI8fIAwGH0NNU1l0sk9BASJi3A=; b=gvXfkrzB0ykZ14nxSnm5jllPyjtwhGHCbBPaSWYJaj5jYJHpXPUlqla9OazExNqxN8 u0t2OwQ4bSJPTVv4pOeWGOXRKknBFU6AOURDSCLh+gR/811pcSjYhbr59VHAichln47Y YMzQV67nMELeJUnD/1g8/+fqumr+0WoYr8B09tyqKSpemAOiSz39Bcjy42JvfMpzS6sg f9WTaO05VDq1PWeIQUnqfoqrH2ibC/04qHloKBovQbmKfW5/jGZ/JVTNipTX8122NNRZ vnlf0kHN6ahSpgCzi/c6WD/fF841/+uxK6qa6V4iQ86zAcVb7StsMbH4AtEmrqeRzqLG 9cnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=m05C5aXu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si2770673ejl.612.2021.08.26.11.06.22; Thu, 26 Aug 2021 11:06:50 -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=@google.com header.s=20161025 header.b=m05C5aXu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243217AbhHZSCL (ORCPT + 99 others); Thu, 26 Aug 2021 14:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbhHZSCJ (ORCPT ); Thu, 26 Aug 2021 14:02:09 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 660C3C0613C1 for ; Thu, 26 Aug 2021 11:01:20 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id 28-20020a17090a031cb0290178dcd8a4d1so6419904pje.0 for ; Thu, 26 Aug 2021 11:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QgZbnxVtGJ1vU/xYWeI8fIAwGH0NNU1l0sk9BASJi3A=; b=m05C5aXu8Pz/nvLpy6GaHwayrmqJ1a0LQNiWk7QGQicePlSFWGwaghG+4McxbSm/uA LYz0gR0yUdFu5PZiWDKnEuWGwS3vvHlMyd5bS3rnlFQsYutpCNBW8v/D3gUzUbdG2hxp LYncdVHUeJ9xl7BV7uFRCTfwRKYT9JmKaSckDYn4slA4i0UA7b91GCS6oAXm0D05Yi3d NISu2BjvNbgkcTqo0jsE5poaEDLF21tzV1+hMdSjyi/3gVdvXIJcnV4EetWmHgIReyhs NkOOQuxwH2oaCqTHwnpRtstgz4c2/WeUCHh2cOSRt140wh6NUGK5T2I5NyhLTP1EuLGy gUWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QgZbnxVtGJ1vU/xYWeI8fIAwGH0NNU1l0sk9BASJi3A=; b=iAg3xGICsrTOVXkRN7lDbi2SONzNI5FsJcJbftOnkjGiu77zSwGlk456o4C5vMl3Zc 8eCpS9CR7DFekOqosGTVbVmb51y6c2ESM2CmbNK5wR26lTlm7hW4ht3v4gi3AVBahKFZ KVbE6VUTcu8ELhLIgb4MG5A5Icg3pusi4X8jE9pso3Jw/YkBqMRhmbjx/6BZVqc+/BA6 6VCHfKJS203DpJzYA5+vY9dEZzl4+5XQt9N2LPDHuBVm9sD5IiIe08kDeqUGcCbidDXw ooBLVAlOBJeXLMX3jJwGap5TLFsA4XOPrVmT4p4Gawqq77Vsq4+zuTmqhg5L1ef0m1OY JgDw== X-Gm-Message-State: AOAM533hno34wLz+JKUU0YDK5MeeZ4zXw6YNTsgGUhJp83F+lHaAnMMS qEEV+4N/xp+oX5ibaCxSqmpt5g== X-Received: by 2002:a17:902:684d:b0:138:7bed:7471 with SMTP id f13-20020a170902684d00b001387bed7471mr4723273pln.68.1630000879595; Thu, 26 Aug 2021 11:01:19 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id u25sm3503724pfn.209.2021.08.26.11.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 11:01:19 -0700 (PDT) Date: Thu, 26 Aug 2021 18:01:15 +0000 From: Sean Christopherson To: Eduardo Habkost Cc: Vitaly Kuznetsov , Maxim Levitsky , kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li , Jim Mattson , "Dr. David Alan Gilbert" , Nitesh Narayan Lal , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/4] KVM: x86: Fix stack-out-of-bounds memory access from ioapic_write_indirect() Message-ID: References: <87mtp7jowv.fsf@vitty.brq.redhat.com> <87k0kakip9.fsf@vitty.brq.redhat.com> <2df0b6d18115fb7f2701587b7937d8ddae38e36a.camel@redhat.com> <87h7fej5ov.fsf@vitty.brq.redhat.com> <36b6656637d1e6aaa2ab5098f7ebc27644466294.camel@redhat.com> <87bl5lkgfm.fsf@vitty.brq.redhat.com> <87tujcidka.fsf@vitty.brq.redhat.com> <20210826145210.gpfbiagntwoswrzp@habkost.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210826145210.gpfbiagntwoswrzp@habkost.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 26, 2021, Eduardo Habkost wrote: > > @@ -918,7 +918,7 @@ static bool kvm_apic_is_broadcast_dest(struct kvm *kvm, struct kvm_lapic **src, > > static inline bool kvm_apic_map_get_dest_lapic(struct kvm *kvm, > > struct kvm_lapic **src, struct kvm_lapic_irq *irq, > > struct kvm_apic_map *map, struct kvm_lapic ***dst, > > - unsigned long *bitmap) > > + unsigned long *bitmap64) > > You can communicate the expected bitmap size to the compiler > without typedefs if using DECLARE_BITMAP inside the function > parameter list is acceptable coding style (is it?). > > For example, the following would have allowed the compiler to > catch the bug you are fixing: > > Signed-off-by: Eduardo Habkost > --- > diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h > index d7c25d0c1354..e8c64747121a 100644 > --- a/arch/x86/kvm/lapic.h > +++ b/arch/x86/kvm/lapic.h > @@ -236,7 +236,7 @@ bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector); > void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu); > > void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq, > - unsigned long *vcpu_bitmap); > + DECLARE_BITMAP(vcpu_bitmap, KVM_MAX_VCPUS)); > > bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq, > struct kvm_vcpu **dest_vcpu); > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 76fb00921203..1df113894cba 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1166,7 +1166,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, > * each available vcpu to identify the same. > */ > void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq, > - unsigned long *vcpu_bitmap) > + DECLARE_BITMAP(vcpu_bitmap, KVM_MAX_VCPUS)) > { > struct kvm_lapic **dest_vcpu = NULL; > struct kvm_lapic *src = NULL; Sadly, that would not have actually caught the bug. In C++, an array param does indeed have a fixed size, but in C an array param is nothing more than syntatic sugar that is demoted to a plain ol' pointer. E.g. gcc-10 and clang-11 both happily compile with "DECLARE_BITMAP(vcpu_bitmap, 0)" and the original single "unsigned long vcpu_bitmap". Maybe there are gcc extensions to enforce array sizes? But if there are, they are not (yet) enabled for kernel builds.