From patchwork Sat Aug 26 23:24:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 717231 Delivered-To: patch@linaro.org Received: by 2002:a5d:688a:0:b0:317:ecd7:513f with SMTP id h10csp547108wru; Sat, 26 Aug 2023 16:25:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX6W+5Z2lYu26apptvR1NkEQLIwwnUy6h2ebr2frFERZTv2gHMsqOqp40lS/IMvkxJ+Ru2 X-Received: by 2002:a0c:e001:0:b0:64e:c9b7:de03 with SMTP id j1-20020a0ce001000000b0064ec9b7de03mr19502391qvk.58.1693092319591; Sat, 26 Aug 2023 16:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693092319; cv=none; d=google.com; s=arc-20160816; b=eceVsx3JCaeAb8XqUasOJxYGV8HFq5STDLJYM7I+yMtHCREO66NQSPV9o6geTiTpdD yd6KGW+P36axbI7YQMV+5VcjScdRbrf/Ofp3PhX3FMNnuGoNZgGyYEj/FGv+LI3Y1xIu jTBTwpnj6qP80v/fP9SeQcBqH34caLv1fKGm6jMSexm4HwtiXKJ+I7S/dHrgUU9E84st slFZ6mVBw8xVRgW/Fm+NjwGixEKZ3EjTr/prwUc/KuFXCzN8yF6QKiwA5WbrnlfFf9w1 XtaMhsLZWAXP4CcIVmnfH+4ZbOADWR1TVo0ApzN+ImyO10011H/1i+/g2CRnKw9I1ree A21A== 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:dkim-signature; bh=lAdtNsi8ueSm/FaTXl8r9wCJNZiral8qMJdVDfCEFMk=; fh=fuBYewipBenZDUITvBadSj9IJzxQGV99ZSsGoAYZmvE=; b=FLGfYlhy1ZQRka3OuPjnM3PXIxgJP4LbSlnXZ/uS5nQwymg+S8Tqjqx2saUjP9igEy B7S7OKrK8pD4D1vM8L+BcZ1vOWhgDXY3cxm/RCUOLmBeSrrK66CHP3DZyU+7qh6rZj6y sYuTHgBRGfqa1WRipbU4X3+ibjkSkX/UoK/aMZic8Mbfuk7tsuTtsw8FacRKxbh+CThl +mqcdUkMWxcBdPsbnGuo87RjfBdz9ItsHf6G0bXT6KSwS5Cs+EGijS/bu1p1MCpwblQz HjR04U3ZB6ccGKe1ctgzaILJ9ViYS0CsftuWV5CVn+izRhvYud7yGnAaZX7Zx/631ifE 7t+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bj7QkS7h; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fh3-20020a0562141a0300b00626102d23d4si3183317qvb.565.2023.08.26.16.25.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Aug 2023 16:25:19 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Bj7QkS7h; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qa2dw-0000Sg-Ns; Sat, 26 Aug 2023 19:24:36 -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 1qa2dj-0000RF-CX for qemu-devel@nongnu.org; Sat, 26 Aug 2023 19:24:24 -0400 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qa2dh-00066K-2i for qemu-devel@nongnu.org; Sat, 26 Aug 2023 19:24:23 -0400 Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3a7d4030621so1308286b6e.3 for ; Sat, 26 Aug 2023 16:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693092260; x=1693697060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lAdtNsi8ueSm/FaTXl8r9wCJNZiral8qMJdVDfCEFMk=; b=Bj7QkS7hD9216l11I3EMVFauRe9ao8eKIoZ4dWgTJlCkCMGOUHC/l9h7+sA8vtK5RQ dmiumzA6SOYPk0/tBUZ0LIzL09B39pcjq+E8F02QgGGgx7Bmx4eAyaMxlIcn4O/50bd7 smVzm0gNsai3hWpV+nj6rQmziJbJ446R/V4J3MBrSgQu/yGaWLyl5qTnY5dD9rFJdeyV RNvOI7q56azjBiA2GAfL5Ytu+DowT1Y3ZUID5Byk9bInJMvZ2gU323K1cGJoQ634LZ2l FNC1CvJwSOJnsl97g42IAMW4xR9xRFNtsVirNRcXnNOG/7/TXPCqbrhe6wr3YfMwUX7X 3BVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693092260; x=1693697060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lAdtNsi8ueSm/FaTXl8r9wCJNZiral8qMJdVDfCEFMk=; b=S+EpyMcJLt8crxkCjKW4cD3NirNWJzLQphiZa+KhoP79qcJJo8Y7pYIqLZzdoBqSEu gv1P0Tj8XWgvKACi+y6Pw5/J84nFJgnPWc2TS7cy7Uj23FdfCT5Ha702QFw/0DaiKEZK Y/W1uvJ3QwGUJD1MDRHTSd1/SlWNUVIe7T67a1gDVgeU8LwhF7UXwzxMx5F0Zk3cQXuA VqoHZ0kgbD8y0BFKzXbVmzXYEJo/ZBGOzz24dbyZTfnYHF3mit4kR+spu8r0sy+yvJ2j KxfEWwzpgwM7KHzZhj0Y8Bqcc3CcwJoBSV3YHHTut5cdnXd7V0Je9HTIFdG84xlr580b Rtdg== X-Gm-Message-State: AOJu0YxHsDUSA37sBpCAU9Nrn4YfYbZxbEU3k3IyZjEln9UfmusJSoAH uJosSP8KwEWKLbLQv577YdAmVFxIWwWqRGUTHu4= X-Received: by 2002:a54:4f03:0:b0:3a8:443b:d87b with SMTP id e3-20020a544f03000000b003a8443bd87bmr7235361oiy.34.1693092259406; Sat, 26 Aug 2023 16:24:19 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id u9-20020a63a909000000b005633311c70dsm4226472pge.32.2023.08.26.16.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Aug 2023 16:24:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, pbonzini@redhat.com, alex.bennee@linaro.org Subject: [PATCH 1/3] softmmu: Assert data in bounds in iotlb_to_section Date: Sat, 26 Aug 2023 16:24:13 -0700 Message-Id: <20230826232415.80233-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230826232415.80233-1-richard.henderson@linaro.org> References: <20230826232415.80233-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::232; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x232.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 Suggested-by: Alex Bennée Signed-off-by: Richard Henderson Acked-by: Alex Bennée --- softmmu/physmem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; - return §ions[index & ~TARGET_PAGE_MASK]; + assert(section_index < d->map.sections_nb); + ret = d->map.sections + section_index; + assert(ret->mr); + assert(ret->mr->ops); + + return ret; } static void io_mem_init(void)