From patchwork Sat Sep 9 10:27:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 721079 Delivered-To: patch@linaro.org Received: by 2002:adf:f64d:0:b0:31d:da82:a3b4 with SMTP id x13csp200319wrp; Sat, 9 Sep 2023 03:29:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhTQP8HxHz/pMbgN8Gh6ZSMFHBGUIMZ2UhUs8EBMuqcsv0/e7OOC7gP2sjj6/KZLVXQEH1 X-Received: by 2002:a05:620a:2a0b:b0:770:58e2:a105 with SMTP id o11-20020a05620a2a0b00b0077058e2a105mr6087363qkp.31.1694255361186; Sat, 09 Sep 2023 03:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694255361; cv=none; d=google.com; s=arc-20160816; b=IdVkFr2Ioef2YmUKGm8d1l5EOj4iVtTOm5TKvrh+ioA8aXf5RmmEm3SP1wYNaS2Dmq XyWSgWZvS4B/jtudhVBgZToTurY7TiC8L1soafbeYAWXH7VV6u/l+9sVlmMAvGPeVHjl kjvqqZX0dBeYifYs6qfcx2Q2GPtZO1nYeAb1DccWRdweFUAOLV4rFJThEfzLcoGxmHYa wieCfKYH0p938bi2YuldoEvTr+WNtHuCj9OoIJpFV8h8c3Ya2mab045oVDmcu304eavL Hf+6dwlO9zhZWrBhrGy7Fqh/J+sbFnxB71jKeruw+X8yWmHIY5uNdlGQupUXa1/tOnu2 aR0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=ypnDFDsJZIWzchMv879oWvP0Tad3AwBP4wXHdfVqt4g=; fh=fA8wXgZkOijV3QzeJqIqYxlGqKQb9nNVVJRQwjQ6hao=; b=tNPjfWX5wS/BisPtd78Iv+6+rYfUMDhRSypHTKmBtHuwwEIG/imH4wI909gAhvqUO5 gvEQPPIPMyoYNQ3L5uCXiDmIq7ILgA7P7AImwXnqJ3D2CJ23Yhx5FJW6F3PahPCJPm7/ EGoJ4/3rsuSAGuguBLPHj3is/ioAVQ9w1570jJM8TdbJGrAclNlOs6ttQKitlse1nt0M Hv95KdxYfRT12fHHPtB23wBlWIcB7imbpKAHjFe5Rf1IPRMIuUSSbVWXsrwS/96SVG4j l0ELAc1aKbIgH0r2qDOeYpPIiL7/LjLGSgTU+uUW4zTph8vmaUrY38pUvcpNxrAmXKnt I/wQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ot20-20020a05620a819400b0076daa65c8adsi2156292qkn.430.2023.09.09.03.29.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Sep 2023 03:29:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qevCN-00076E-Qy; Sat, 09 Sep 2023 06:28:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qevCM-00074z-HJ; Sat, 09 Sep 2023 06:28:18 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qevCK-0004Tw-2S; Sat, 09 Sep 2023 06:28:18 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 401682049E; Sat, 9 Sep 2023 13:28:49 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 4758926CFC; Sat, 9 Sep 2023 13:27:58 +0300 (MSK) Received: (nullmailer pid 346655 invoked by uid 1000); Sat, 09 Sep 2023 10:27:57 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , Michael Tokarev Subject: [Stable-8.1.1 11/34] softmmu: Assert data in bounds in iotlb_to_section Date: Sat, 9 Sep 2023 13:27:04 +0300 Message-Id: <20230909102747.346522-11-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Acked-by: Alex Bennée Suggested-by: Alex Bennée Signed-off-by: Richard Henderson (cherry picked from commit 86e4f93d827d3c1efd00cd8a906e38a2c0f2b5bc) Signed-off-by: Michael Tokarev diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 3df73542e1..7597dc1c39 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2413,9 +2413,15 @@ MemoryRegionSection *iotlb_to_section(CPUState *cpu, int asidx = cpu_asidx_from_attrs(cpu, attrs); CPUAddressSpace *cpuas = &cpu->cpu_ases[asidx]; AddressSpaceDispatch *d = qatomic_rcu_read(&cpuas->memory_dispatch); - MemoryRegionSection *sections = d->map.sections; + int section_index = index & ~TARGET_PAGE_MASK; + MemoryRegionSection *ret; + + assert(section_index < d->map.sections_nb); + ret = d->map.sections + section_index; + assert(ret->mr); + assert(ret->mr->ops); - return §ions[index & ~TARGET_PAGE_MASK]; + return ret; } static void io_mem_init(void)