Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp419509imm; Wed, 29 Aug 2018 03:25:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaFCIrix5YwkGWkMSaWTt3r3S4K6z9BmJ0hIao4cery4S0htrUHkRaX4jkp6Si61eO4WqCE X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr5371359plb.86.1535538336475; Wed, 29 Aug 2018 03:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535538336; cv=none; d=google.com; s=arc-20160816; b=rRfh1MkQK4XAW25DnlyN9VAAAZIeJwTvH7XsOOPRmt/UwTip0gXvUeKr99o41dPq+i ZUsIEY8Kw1UX7ucQjWtft9aU1Ja3c3h21ANVXAmmKpbJniVa8x8btJ0LnOiY36SKCVsm PfpzLuYF8y8nmBrhmnsaniqBK64tkp1qwZN4jYeM5d1zbwaeMfxRwqk5DIdDpg6DNxsU 1bAgrfyDSKOfz5BWLd9NoaDk5H7vCt0L5f9dkd6WTooawRkOonfhAKhbDfkojO3QkM2+ +2W85XOVTXFDoEN5hYVwvebpzjVNnmezgpzvxx+Da44b29xz5M0Y6KJtb/OSZn7veMHo /e1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=KzrJP4isoB6FmN9vrxNHMZqkcX8et6IZ/Tw04la4lgU=; b=xWyUQSB3D1cL4zI2e3Yxjj05X3fAhqoOjJPp3LgeefFeDjkd+pfFS87MXUZ7EWY5Tx igEPz2fL/fM6R+WZH3y8PBY006NICnBUW3vSReYcsfpE+IuGNXnd36TJ9Ax/jwzDOTPu aJBFrMATR+D0NffY6R/Bmmwo0XwtL/VjG2wXNLbZKBVol+cWJhMQJBQb74NeFh4gHg8K yE/RHBvQVbi1VVHwDe3IfJFkzEp6WYrr770dEg8r9CA4wCN3iaBJi3RP870wmjGOBMxC w2LooJBLmPZOepziVIdeKvS9fZvnRgjTj6ZN14aZoJfvUK8dxOveyt1Qvt9pZ3HS3gNM jikg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=edMvYHB3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e37-v6si3804320plb.313.2018.08.29.03.25.20; Wed, 29 Aug 2018 03:25:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=edMvYHB3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727510AbeH2OTX (ORCPT + 99 others); Wed, 29 Aug 2018 10:19:23 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:38155 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbeH2OTW (ORCPT ); Wed, 29 Aug 2018 10:19:22 -0400 Received: by mail-oi0-f65.google.com with SMTP id x197-v6so8222185oix.5; Wed, 29 Aug 2018 03:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=KzrJP4isoB6FmN9vrxNHMZqkcX8et6IZ/Tw04la4lgU=; b=edMvYHB3Pn/DZPxGveRX5uejCyr/rHxj+GeSMcxCmoohvwoKkTNXaq+NV1Lx3+9dcm NtOqFrCFYpzl7Fi9gNuGfyVvaOF5GfDKE/iaQ1ROr+P/JWjpUKf1QFhW31iLw3XsCPjI sVoWnDrg1czP+zdQGeN/97qPdsJ7QY5RRHXTxjMfEzgj94Okxvm8L06ASNOMpV3U9J/r fhbmBHhYFboGbcSfSUZEW9FH+PnN8LZZpEeJQE9R5tzm51vNTl4iI8cf7VBJkwEE9JYg 5rk1GAErQmGPrxLhxSZezntzbRzyLnVhFM51d7Tj47QDQgb+vSk5Nxh/TpFdhlIYX8BX gpkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KzrJP4isoB6FmN9vrxNHMZqkcX8et6IZ/Tw04la4lgU=; b=JrrwL6YUWKErKRB6njbtg+f4ODM5tQVUgK6rdmy3fCj/b8pJ3wPciMkOL6WW1Ib6hy L9qjxfoSku85JWFWMaTP3r/iTpfL5hcaTbqMDTDI5I1a9N0mDnAu4etennIvtuhJ+D17 piOpQcaE3/3AB71f/0ST6dCyfYikKgM0ysWkOYrMMLf02PjHEJ/J5KifFbSoJ+oZ+VOh PYDacTdE+8TC3A85mZ0Ms9cwgygjqAUR2NDsYyX92xa5viIgvKa9hO9KY43p4uz2burb pHCOvfnGU8Jr2aID3SDWFIa6xXJeSqmm1lepVY7FwOHGlgTFyw40QJvz5GzdDp6rCJp4 LHAw== X-Gm-Message-State: APzg51ADvddOqECW9bJjW2VdoT1xOyxl26xSLoeZrf+sDgTFndgA2TkN CzfloAa2B80agoQ+auqLR5Gcn5P9Xfm2lRYatC0= X-Received: by 2002:aca:dc82:: with SMTP id t124-v6mr1957066oig.189.1535538190001; Wed, 29 Aug 2018 03:23:10 -0700 (PDT) MIME-Version: 1.0 References: <1535521943-5547-1-git-send-email-wanpengli@tencent.com> <20180829101205.jsp53e2wq7fc6ukd@mwanda> <20180829101822.qo3u7lsmghs3kcuf@mwanda> In-Reply-To: <20180829101822.qo3u7lsmghs3kcuf@mwanda> From: Wanpeng Li Date: Wed, 29 Aug 2018 18:23:08 +0800 Message-ID: Subject: Re: [PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access To: Dan Carpenter Cc: Liran Alon , LKML , kvm , Paolo Bonzini , Radim Krcmar Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Aug 2018 at 18:18, Dan Carpenter wrot= e: > > On Wed, Aug 29, 2018 at 01:12:05PM +0300, Dan Carpenter wrote: > > On Wed, Aug 29, 2018 at 12:05:06PM +0300, Liran Alon wrote: > > > > arch/x86/kvm/lapic.c | 17 +++++++++++++---- > > > > 1 file changed, 13 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > > > > index 0cefba2..86e933c 100644 > > > > --- a/arch/x86/kvm/lapic.c > > > > +++ b/arch/x86/kvm/lapic.c > > > > @@ -571,18 +571,27 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned= long ipi_bitmap_low, > > > > rcu_read_lock(); > > > > map =3D rcu_dereference(kvm->arch.apic_map); > > > > > > > > + if (unlikely((s32)(map->max_apic_id - __fls(ipi_bitmap_low)) < mi= n)) > > > > + goto out; > > > > > > I personally think =E2=80=9Cif ((min + __fls(ipi_bitmap_low)) > map->= max_apic_id)=E2=80=9D is more readable. > > > But that=E2=80=99s just a matter of taste :) > > > > That's an integer overflow. > > > > But I do prefer to put the variable on the left. The truth is that som= e > > Smatch checks just ignore code which is backwards written because > > otherwise you have to write duplicate code and the most code is written > > with the variable on the left. > > > > if (min > (s32)(map->max_apic_id - __fls(ipi_bitmap_low)) > > Wait, the (s32) cast doesn't make sense. We want negative min values to > be treated as invalid. In v2, how about: if (unlikely(min > map->max_apic_id || (min + __fls(ipi_bitmap_low)) > map->max_apic_id)) goto out; 0xFFFFFFFF is converted to int min =3D -1; Regards, Wanpeng Li