Received: by 2002:a17:906:5814:b0:a6f:8e2c:4d9d with SMTP id m20csp173438ejq; Thu, 20 Jun 2024 17:17:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXX3YA/ckG/1/7ikGNWqVY8Wc8qT6hUvzz2kd5Nty61XkRIVZ32sXT5UerImzt0S2k2Ja+YhWN21z1zh6DGvvmOtHvOlAYs X-Google-Smtp-Source: AGHT+IGHn1yJX3LZDO3wscWkbSznO04l5NZtDuPC3hQ/k5SqJgl8eBUkfP/rUhVFUUuaf9TOLu9y X-Received: by 2002:ad4:51d2:0:b0:6b5:760:6818 with SMTP id 6a1803df08f44-6b507606c0fmr57872976d6.65.1718929078208; Thu, 20 Jun 2024 17:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718929078; cv=none; d=google.com; s=arc-20160816; b=jSZaYlpnUgDdXB9St9Yg7sZBajvGYpqF0ofqUi8kL/7+DaSkNQIT2yO9hLZdeIDFWU RKAenm+iZd/kXNxN4V2ZyOwZqDaVId2KZ5lfNLABCVN7nMUK9S8fjdFEzmYs/CEoeoqh ObTWGiXsR/TzIvXoScCuPtIC4eMgsgb+b8fzXZGvjVIKO3xmb9/ioGf2o5+c+BCOVi6o U9RbEG+eikaAdo7P3oYobmbNyIPbHK+fL5G6zzcNpfCaVqfKkvD/2vpj/C1SElWvItUB 20XW6Agh2Cxak9bJ38jFU9tR3Hh4SdB5S1iVli4ZRr3uiVi9yVj4PKXTTnLQvSCtkoxQ Kesw== 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:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=8xdua9NJKnabCVQLyXKwp7FRMc4pNCd8IydECavlhh0=; fh=x5XuGiwkbRHK8ZRroBkdHiOQErlFxOugbQQGZXggGWU=; b=M/BKfx7nnHNMX6AQDcZNJypdw7GcIdl0yrAN3tW6nisE5NB4vI1lDV73qeGCgwbXO5 j/sKp7aCiqfYECRhIbYNOm4bkqJmqqYly4bBgyKdQKDE5mUslOEE3yYOpesDerqOBIIe erggWCUP3A8D3ySjgQDyiBBjg8lFT8dxZX5OPIAG2sAdMacNU9FfgDBnRsrwPYRKN5dx aKHTrXcCbD3k/NXyF/woWAZkkuG9iKGoY79/YzubfmmMtaek9KlvgIinc6MUz2VvzDHX N3g9pZEyN4BHUzBoFef31X4/WsbPvLg9L+UsyZfnDgJE1f9iqM0w9LPEVPFHgkHcnxoT 2R/Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=FQL2H0bE; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6b51eceb875si4175686d6.45.2024.06.20.17.17.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jun 2024 17:17:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=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=@codeconstruct.com.au header.s=2022a header.b=FQL2H0bE; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKRxv-0006Bq-Ig; Thu, 20 Jun 2024 20:17: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 1sKRxu-0006BH-2h; Thu, 20 Jun 2024 20:17:18 -0400 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sKRxq-0002iS-Ib; Thu, 20 Jun 2024 20:17:17 -0400 Received: from [192.168.68.112] (ppp118-210-79-194.adl-adc-lon-bras32.tpg.internode.on.net [118.210.79.194]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id C7CBA200DD; Fri, 21 Jun 2024 08:17:00 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1718929023; bh=8xdua9NJKnabCVQLyXKwp7FRMc4pNCd8IydECavlhh0=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=FQL2H0bEA5HeIuobAvzwTp4V0jspWN2kgGQsxyDIHomX60pmhJhfov9SfaLbLw0+G F0WKr/Z4BJ2u+E4rKpgIDC2i8vo73YZq5dUrhpz2MTiUfcVhejbFxU+w/0i+8NoZGB +Lgc0PMb8P5cVopBi06SkG2y3a4ZSR7WzBmFXXOimXut14PzeUVWvoJQ/x3R6nm/nj X8+lw9vwK8dOOP8vcdI8dZEgAg4fu0z3WeF4CxyPCNxhAuJXWoJtbX4065BUEnhkL4 UMjG/YhUav5uo1k7SLonRLB2TAOsxwGRqrI41nb8nMHwpse04HfiGjliqqc9zo35Kb ZvJOKzpL9/2aA== Message-ID: Subject: Re: [PATCH v4] hw/gpio/aspeed: Add reg_table_count to AspeedGPIOClass From: Andrew Jeffery To: Zheyu Ma , =?ISO-8859-1?Q?C=E9dric?= Le Goater , Peter Maydell , Joel Stanley Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Fri, 21 Jun 2024 09:46:58 +0930 In-Reply-To: <20240620140239.375338-1-zheyuma97@gmail.com> References: <20240620140239.375338-1-zheyuma97@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Received-SPF: pass client-ip=203.29.241.158; envelope-from=andrew@codeconstruct.com.au; helo=codeconstruct.com.au 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@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-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: 7er9M1rw3hrC On Thu, 2024-06-20 at 16:02 +0200, Zheyu Ma wrote: > ASan detected a global-buffer-overflow error in the aspeed_gpio_read() > function. This issue occurred when reading beyond the bounds of the > reg_table. >=20 > To enhance the safety and maintainability of the Aspeed GPIO code, this c= ommit > introduces a reg_table_count member to the AspeedGPIOClass structure. Thi= s > change ensures that the size of the GPIO register table is explicitly tra= cked > and initialized, reducing the risk of errors if new register tables are > introduced in the future. >=20 > Reproducer: > cat << EOF | qemu-system-aarch64 -display none \ > -machine accel=3Dqtest, -m 512M -machine ast1030-evb -qtest stdio > readq 0x7e780272 > EOF >=20 > ASAN log indicating the issue: > =3D=3D2602930=3D=3DERROR: AddressSanitizer: global-buffer-overflow on add= ress 0x55a5da29e128 at pc 0x55a5d700dc62 bp 0x7fff096c4e90 sp 0x7fff096c4e8= 8 > READ of size 2 at 0x55a5da29e128 thread T0 > #0 0x55a5d700dc61 in aspeed_gpio_read hw/gpio/aspeed_gpio.c:564:14 > #1 0x55a5d933f3ab in memory_region_read_accessor system/memory.c:445:= 11 > #2 0x55a5d92fba40 in access_with_adjusted_size system/memory.c:573:18 > #3 0x55a5d92f842c in memory_region_dispatch_read1 system/memory.c:142= 6:16 > #4 0x55a5d92f7b68 in memory_region_dispatch_read system/memory.c:1459= :9 > #5 0x55a5d9376ad1 in flatview_read_continue_step system/physmem.c:283= 6:18 > #6 0x55a5d9376399 in flatview_read_continue system/physmem.c:2877:19 > #7 0x55a5d93775b8 in flatview_read system/physmem.c:2907:12 >=20 > Signed-off-by: Zheyu Ma Reviewed-by: Andrew Jeffery