Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp328746pxf; Thu, 1 Apr 2021 02:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz49k9bZpvJm8jcKD8QU4flgJL15Vzz7VfKxenU7cvxfH/BngY7dMFyY+6DaGpHLCKr57nU X-Received: by 2002:a17:906:d10b:: with SMTP id b11mr8078344ejz.144.1617268209478; Thu, 01 Apr 2021 02:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617268209; cv=none; d=google.com; s=arc-20160816; b=ej76ou9k+GPvWrShmu2SUbFCYENC9iGGGefAZ06uYy2abfT/HFhkLlznileKJwJ2zP OMkPn4nJ3rWeCnIgbFSK89Fu1LMN40uOMlttqEtJEqJbAqa/50rDcvPFegi4lsmhIcyV jxJR8oGV653O5dyL072bG4doCA/F4Ws6s6SlmJt35ylozO7woHFQUl52euv2MctQA/9P pwUgURID/iTHi3wddZg4gkRnEyzuqCIi88+C1co5kwJUuRxWHq0Nmq3hSlyd3t9IQw6D XSnsWqDVTWczXbghmySG1xMZ7WZsUeLvMxrTM0oxr09oHcrQ9iCbBTJ/0CpIJXMaBms6 uEkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=SH8q6v7mosb9ZWkhGf8eANcJIvuHX/dVnNgdkFE16jE=; b=elsVajEvuXBOvRg8A/NOcmoZQ2Tc9qrj43i5TYpoBcDR6Sr1R83NGViJaz9oArtH/f zoS6BHSFh6MpkoB7lbpNb64nBM2AKwBItLkF0KDkILclUFItomPcth0C9f9SAG/K0Jjy TPpU2Re+XobRcblYQ1pMVIV3ZcLaV37rRuHnhvl3mf0k8CxdCjYR8F4cR1GNyiEoNDOL JzNJC6uXZrFt51wcBANChYa02ciA46pGvU7WWBjhloQ0Lk4fN7wYHnuYDKCs6U2errgP pXjvJzG9hMHKNsbBBX+ADiRhyqGJeHdhywHHM2CaE2lXfGoHrPpqYSCUQzr6+PP9BxG+ BgIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JyuCQVPF; 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 e13si4007885edz.432.2021.04.01.02.09.46; Thu, 01 Apr 2021 02:10:09 -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=JyuCQVPF; 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 S233700AbhDAJIU (ORCPT + 99 others); Thu, 1 Apr 2021 05:08:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34490 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233736AbhDAJIR (ORCPT ); Thu, 1 Apr 2021 05:08:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617268097; 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=SH8q6v7mosb9ZWkhGf8eANcJIvuHX/dVnNgdkFE16jE=; b=JyuCQVPFwIp/3uxqt6W7vC6AlxMS+8uw2UNA7rWHqxguau+l+0eazFFlNzbYH4llmylV4k px3LV4973LiLlktBRLaZmI4uSansLUVeRB6Zt1DH2lxIVDRchJIqMpqjNk+pkoMd+fny94 cKGqt2iTSR/KCXwKZVIyxv3+JwWPeTE= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-uhKuSGaPM3abFDfgIEObTQ-1; Thu, 01 Apr 2021 05:08:16 -0400 X-MC-Unique: uhKuSGaPM3abFDfgIEObTQ-1 Received: by mail-ej1-f71.google.com with SMTP id li22so1958458ejb.18 for ; Thu, 01 Apr 2021 02:08:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=SH8q6v7mosb9ZWkhGf8eANcJIvuHX/dVnNgdkFE16jE=; b=byqfzOk63qX4awgE8dzYT8vLQo96+nsG6bdaNRy76dpJ4+DHwDk7uT7ep6YTvor0rP 2mAns8gXzSUB4rO98vw3mBIokjUG/fca7NqScRqFgm7OMBhrdgTZ+sesM7/NB4KqTPf/ tkYiSbkO8Ko9LQaUOTxqS3zVsf2awWnB881Xv2kvmcqJkTEyUJp886FvjBHC56U0j0Iz R+mEzPhFeFEtkUk5Fwt0gWxj8/NqAMMqJCIAtPPjNXaFuwwOHyxWHH+lFDfYmnltFnTy TRRolz7VMMgTd7Z0Zs5JRv63H4PjbD30S9hjeKORGEDgHh903FweVgLrE0UG6jawIWHX vERA== X-Gm-Message-State: AOAM530HTYqFBGmoo/8lL6VVSzyp3nLM6WdzScroCzvUcRVCLhB/MAJu ubeSPkeOkir7y0HzJvWMSuUHXrq0eU4dDg3jhDBW5h+Oe4AYNPavTcKZNRSD9bdieq7nx7wNiPn Et+XguMqgL9+CcVYgwt6Bnbnz09jY1wfKztIgvEHQIVQVMdDRc+/WMwJVeVXIJpEdXKT8LfEtXM g/ X-Received: by 2002:aa7:d296:: with SMTP id w22mr9132653edq.150.1617268094974; Thu, 01 Apr 2021 02:08:14 -0700 (PDT) X-Received: by 2002:aa7:d296:: with SMTP id w22mr9132630edq.150.1617268094789; Thu, 01 Apr 2021 02:08:14 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id x4sm2967618edd.58.2021.04.01.02.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 02:08:14 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , Yang Li Cc: pbonzini@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86: Fix potential memory access error In-Reply-To: References: <1617182122-112315-1-git-send-email-yang.lee@linux.alibaba.com> Date: Thu, 01 Apr 2021 11:08:13 +0200 Message-ID: <87mtuis77m.fsf@vitty.brq.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: > On Wed, Mar 31, 2021, Yang Li wrote: >> Using __set_bit() to set a bit in an integer is not a good idea, since >> the function expects an unsigned long as argument, which can be 64bit wide. >> Coverity reports this problem as >> >> High:Out-of-bounds access(INCOMPATIBLE_CAST) >> CWE119: Out-of-bounds access to a scalar >> Pointer "&vcpu->arch.regs_avail" points to an object whose effective >> type is "unsigned int" (32 bits, unsigned) but is dereferenced as a >> wider "unsigned long" (64 bits, unsigned). This may lead to memory >> corruption. >> >> /home/heyuan.shy/git-repo/linux/arch/x86/kvm/kvm_cache_regs.h: >> kvm_register_is_available >> >> Just use BIT instead. > > Meh, we're hosed either way. Using BIT() will either result in undefined > behavior due to SHL shifting beyond the size of a u64, or setting random bits > if the truncated shift ends up being less than 63. > A stupid question: why can't we just make 'regs_avail'/'regs_dirty' 'unsigned long' and drop a bunch of '(unsigned long *)' casts? -- Vitaly