Received: by 10.192.165.148 with SMTP id m20csp1226442imm; Wed, 2 May 2018 16:57:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrwoXJJU8WWEl3cemBmH/nvNusW4HUD0XIh41jmmEt/r232BuvSe0uObgWnNqP/sgWF/HY1 X-Received: by 2002:a17:902:10c:: with SMTP id 12-v6mr22000007plb.252.1525305435889; Wed, 02 May 2018 16:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525305435; cv=none; d=google.com; s=arc-20160816; b=VSqn8CU6siz5tWrXSuPeP+HPo4eXaKnoUFCU/nRj42ZR4nBfTlAtxJ8AqMCfljXM94 J8rQAZnqUq5F8Nd9UHxfDyhspiPzbVGsaVsjrqFGXyhVvyzJG1cAZcha7m51VU6Y8Z9p 5fyBMTH3c03vOBxX8IuPdqjSI3bJy0s6pcF62jnbqSheZSbRnM7/C6CXLYKBszGNIKcW kyISjIqBnZSPyKboNadGz3zT9gPjc+YKEw7fe4ZrnpChDhJ8sXp0/rgzxDTA3Gf1P7p6 HXENVcDEOYhOrYsMSo1AS3nXGhq3orfrQnwWb5OqHQUrL35dQ3sw14Md18oHwibErqLc 5KDg== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=WmVolVZZzb7qiMr6ECFJ9TAvpPd4gJdMOH9LrQbCqTE=; b=YPNjfrp+HfKaCpGM4fkOpkKULyxrkecOU5kMNtXXVrjhJ38j40Vb8Z/jeNj48IyuaO lhqigI6KeSxRGo8jC31QkO0S33Pw9kIRgKPImORNqVjCoFjd3r240h09ygmYPQOPry/3 rAQV9HiR4jGic40JvSHW4bL0ALqE56Byu1BDeTF8Z8Ie3F0p63ORAuAtwCd8OqXno33O zVgaML5oLrUn5tUN8teI0FCvgQ+ktt8lV3RRHMvFbdXEYNZbSVVYN8pkr++fp0PlmuHY 1V7R7oOhdmk/VTyADro2t5nW/3Sy4+w0BNvKK5EYBwc+fMH/eyJ9b34hTc1Gln/9T2Mi JUww== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si7184377pfi.360.2018.05.02.16.56.59; Wed, 02 May 2018 16:57:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751841AbeEBX4m (ORCPT + 99 others); Wed, 2 May 2018 19:56:42 -0400 Received: from mga02.intel.com ([134.134.136.20]:36610 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751698AbeEBX4k (ORCPT ); Wed, 2 May 2018 19:56:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 May 2018 16:56:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,356,1520924400"; d="scan'208";a="225337584" Received: from blu2-desk2.ccr.corp.intel.com (HELO [10.0.2.15]) ([10.239.13.1]) by fmsmga006.fm.intel.com with ESMTP; 02 May 2018 16:56:27 -0700 Subject: Re: [RESEND][PATCH] iommu/vt-d: fix shift-out-of-bounds in bug checking To: changbin.du@intel.com, jroedel@suse.de, iommu@lists.linux-foundation.org References: <1524897587-15125-1-git-send-email-changbin.du@intel.com> Cc: linux-kernel@vger.kernel.org From: Lu Baolu Message-ID: <5AEA502B.70502@linux.intel.com> Date: Thu, 3 May 2018 07:56:27 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1524897587-15125-1-git-send-email-changbin.du@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 04/28/2018 02:39 PM, changbin.du@intel.com wrote: > From: Changbin Du > > It allows to flush more than 4GB of device TLBs. So the mask should be > 64bit wide. UBSAN captured this fault as below. > > [ 3.760024] ================================================================================ > [ 3.768440] UBSAN: Undefined behaviour in drivers/iommu/dmar.c:1348:3 > [ 3.774864] shift exponent 64 is too large for 32-bit type 'int' > [ 3.780853] CPU: 2 PID: 0 Comm: swapper/2 Tainted: G U 4.17.0-rc1+ #89 > [ 3.788661] Hardware name: Dell Inc. OptiPlex 7040/0Y7WYT, BIOS 1.2.8 01/26/2016 > [ 3.796034] Call Trace: > [ 3.798472] > [ 3.800479] dump_stack+0x90/0xfb > [ 3.803787] ubsan_epilogue+0x9/0x40 > [ 3.807353] __ubsan_handle_shift_out_of_bounds+0x10e/0x170 > [ 3.812916] ? qi_flush_dev_iotlb+0x124/0x180 > [ 3.817261] qi_flush_dev_iotlb+0x124/0x180 > [ 3.821437] iommu_flush_dev_iotlb+0x94/0xf0 > [ 3.825698] iommu_flush_iova+0x10b/0x1c0 > [ 3.829699] ? fq_ring_free+0x1d0/0x1d0 > [ 3.833527] iova_domain_flush+0x25/0x40 > [ 3.837448] fq_flush_timeout+0x55/0x160 > [ 3.841368] ? fq_ring_free+0x1d0/0x1d0 > [ 3.845200] ? fq_ring_free+0x1d0/0x1d0 > [ 3.849034] call_timer_fn+0xbe/0x310 > [ 3.852696] ? fq_ring_free+0x1d0/0x1d0 > [ 3.856530] run_timer_softirq+0x223/0x6e0 > [ 3.860625] ? sched_clock+0x5/0x10 > [ 3.864108] ? sched_clock+0x5/0x10 > [ 3.867594] __do_softirq+0x1b5/0x6f5 > [ 3.871250] irq_exit+0xd4/0x130 > [ 3.874470] smp_apic_timer_interrupt+0xb8/0x2f0 > [ 3.879075] apic_timer_interrupt+0xf/0x20 > [ 3.883159] > [ 3.885255] RIP: 0010:poll_idle+0x60/0xe7 > [ 3.889252] RSP: 0018:ffffb1b201943e30 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff13 > [ 3.896802] RAX: 0000000080200000 RBX: 000000000000008e RCX: 000000000000001f > [ 3.903918] RDX: 0000000000000000 RSI: 000000002819aa06 RDI: 0000000000000000 > [ 3.911031] RBP: ffff9e93c6b33280 R08: 00000010f717d567 R09: 000000000010d205 > [ 3.918146] R10: ffffb1b201943df8 R11: 0000000000000001 R12: 00000000e01b169d > [ 3.925260] R13: 0000000000000000 R14: ffffffffb12aa400 R15: 0000000000000000 > [ 3.932382] cpuidle_enter_state+0xb4/0x470 > [ 3.936558] do_idle+0x222/0x310 > [ 3.939779] cpu_startup_entry+0x78/0x90 > [ 3.943693] start_secondary+0x205/0x2e0 > [ 3.947607] secondary_startup_64+0xa5/0xb0 > [ 3.951783] ================================================================================ This looks good to me. Best regards, Lu Baolu > Signed-off-by: Changbin Du > --- > drivers/iommu/dmar.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c > index accf5838..e4ae600 100644 > --- a/drivers/iommu/dmar.c > +++ b/drivers/iommu/dmar.c > @@ -1345,7 +1345,7 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep, > struct qi_desc desc; > > if (mask) { > - BUG_ON(addr & ((1 << (VTD_PAGE_SHIFT + mask)) - 1)); > + BUG_ON(addr & ((1ULL << (VTD_PAGE_SHIFT + mask)) - 1)); > addr |= (1ULL << (VTD_PAGE_SHIFT + mask - 1)) - 1; > desc.high = QI_DEV_IOTLB_ADDR(addr) | QI_DEV_IOTLB_SIZE; > } else