From nobody Wed May 8 08:10:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1593712610; cv=none; d=zohomail.com; s=zohoarc; b=ApV5c4xuuUI3b4/G0Gt2Q0bbH1FP6O11rEi4upmRoetjAK5DUGW17VEubDsYZEyZs0MGBprWUgLP9hFq0l6cLaOk9o5BRt3PBFjP6RCs8igzQH+ICxuVLX3xWq5YHiGdI4vq5bbdYtomx+5tdhHU9UPI//VpCZUK0YYXFzuXmjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593712610; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=rQZd24S5VU+V/cof+qwhVwm+IKJe+Jz5EkBoSd9tflA=; b=ab8QvQwTSFZbjCQp/Jct2TZk+rLqK+In9WF5R4NztsQMYIE3ELpbOcbWiSuu68CcfdydNxSDJp+Zb5r5cY+p4O4FdvPLy69HbARTKfEdZIRY0rYIyKao6krFvfy3vNkrzenIQsuQkkYPyZJYsu5oJBkxDUhOYNEm4+8qXSmaaC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593712610304763.7466503941147; Thu, 2 Jul 2020 10:56:50 -0700 (PDT) Received: from localhost ([::1]:45324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jr3S4-0008VT-Mo for importer@patchew.org; Thu, 02 Jul 2020 13:56:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jr3RS-00082N-Im for qemu-devel@nongnu.org; Thu, 02 Jul 2020 13:56:10 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:34546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jr3RQ-0002WE-TF for qemu-devel@nongnu.org; Thu, 02 Jul 2020 13:56:10 -0400 Received: by mail-pf1-x443.google.com with SMTP id u185so10815555pfu.1 for ; Thu, 02 Jul 2020 10:56:08 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id ji2sm8141392pjb.1.2020.07.02.10.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jul 2020 10:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rQZd24S5VU+V/cof+qwhVwm+IKJe+Jz5EkBoSd9tflA=; b=dbfd0rZbLdOFvQpl1MnVp3uvOqNiTGA04gMF6x8GUUkOi7XVnrQwde2UDEE1LYP3x9 HSpBTW3p6gY5vYAlkoGASUr3Wbjcs7q0YspVPMSOfnrIqHhN/7UAszlK1TJVg1wYz8RV fIgQcL9rKuenBRdsE3Q4w6fm9Y3CwhAYOsyv8NAYOTgSiCthprXgW5GIgQUWJA0VtwNz viie7vNoW+wMQAZKTdo3XgfSOJEqZa6lQfkXzCJuA5lvCT/JJLSBm+YinT1VCOQZwwym nMyOWRG2MsvwO5+CBDlH4VTtuV1zeC13zVB7UrCvTgKN/w0NZCcGPy+rRu/xrD7SI6sB womA== 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:date:message-id:mime-version :content-transfer-encoding; bh=rQZd24S5VU+V/cof+qwhVwm+IKJe+Jz5EkBoSd9tflA=; b=nXeFsHyDl0FdQwuy4AeyiL+v/ZAOgdCqxBsQgsuN4d6LRc/0gEZNL9QaULrbaDTi+b 5W+LBoi5AfCCupK9tgEMAlJXnCRVRTOVeeKbsfmIJ9BAFvLiEh6IWoJ9w2cJJgOihdCW UDxZZsKoT/t3k25ggWgfCqf4EhYWTrXg9hSqkC5dDoAyoeueDzZ5Q6K924EUuG46dxjO OILhr56EvywGJ+rr8m+A/OZMb1dMbvATurFt474XDCY7xmB3vqMGVnG/YUE6XTtz28hR schyQXiROvcUjEIFdONmxWRj6IQJE1/IYcuPD3FMrw8LVETq5/wpPtU/Yq6NSvcKz4qE tcJQ== X-Gm-Message-State: AOAM531MnJP6WD8Sl3djkeZnOPebbGnKIXjmeZ7cL/9bNgvI9Ed4krVQ 9dOtvKkb0WKojAeYlWhbLfc1F4WD2FQ= X-Google-Smtp-Source: ABdhPJz2rwdrVxBPrIMxGpsZrnyoZmOgiefcMUI9cQMNQnBr7WpcRc2n7ZJdBH/KZ4N9NVFCKQgCkA== X-Received: by 2002:a62:8688:: with SMTP id x130mr29868613pfd.280.1593712566758; Thu, 02 Jul 2020 10:56:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] target/arm: Fix temp double-free in sve ldr/str Date: Thu, 2 Jul 2020 10:56:05 -0700 Message-Id: <20200702175605.1987125-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" The temp that gets assigned to clean_addr has been allocated with new_tmp_a64, which means that it will be freed at the end of the instruction. Freeing it earlier leads to assertion failure. The loop creates a complication, in which we allocate a new local temp, which does need freeing, and the final code path is shared between the loop and non-loop. Fix this complication by adding new_tmp_a64_local so that the new local temp is freed at the end, and can be treated exactly like the non-loop path. Fixes: bba87d0a0f4 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/translate-a64.h | 1 + target/arm/translate-a64.c | 6 ++++++ target/arm/translate-sve.c | 8 ++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/target/arm/translate-a64.h b/target/arm/translate-a64.h index 49e4865918..647f0c74f6 100644 --- a/target/arm/translate-a64.h +++ b/target/arm/translate-a64.h @@ -30,6 +30,7 @@ void unallocated_encoding(DisasContext *s); } while (0) =20 TCGv_i64 new_tmp_a64(DisasContext *s); +TCGv_i64 new_tmp_a64_local(DisasContext *s); TCGv_i64 new_tmp_a64_zero(DisasContext *s); TCGv_i64 cpu_reg(DisasContext *s, int reg); TCGv_i64 cpu_reg_sp(DisasContext *s, int reg); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 73d753f11f..8c0764957c 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -461,6 +461,12 @@ TCGv_i64 new_tmp_a64(DisasContext *s) return s->tmp_a64[s->tmp_a64_count++] =3D tcg_temp_new_i64(); } =20 +TCGv_i64 new_tmp_a64_local(DisasContext *s) +{ + assert(s->tmp_a64_count < TMP_A64_MAX); + return s->tmp_a64[s->tmp_a64_count++] =3D tcg_temp_local_new_i64(); +} + TCGv_i64 new_tmp_a64_zero(DisasContext *s) { TCGv_i64 t =3D new_tmp_a64(s); diff --git a/target/arm/translate-sve.c b/target/arm/translate-sve.c index f318ca265f..08f0fd15b2 100644 --- a/target/arm/translate-sve.c +++ b/target/arm/translate-sve.c @@ -4372,9 +4372,8 @@ static void do_ldr(DisasContext *s, uint32_t vofs, in= t len, int rn, int imm) =20 /* Copy the clean address into a local temp, live across the loop.= */ t0 =3D clean_addr; - clean_addr =3D tcg_temp_local_new_i64(); + clean_addr =3D new_tmp_a64_local(s); tcg_gen_mov_i64(clean_addr, t0); - tcg_temp_free_i64(t0); =20 gen_set_label(loop); =20 @@ -4422,7 +4421,6 @@ static void do_ldr(DisasContext *s, uint32_t vofs, in= t len, int rn, int imm) tcg_gen_st_i64(t0, cpu_env, vofs + len_align); tcg_temp_free_i64(t0); } - tcg_temp_free_i64(clean_addr); } =20 /* Similarly for stores. */ @@ -4463,9 +4461,8 @@ static void do_str(DisasContext *s, uint32_t vofs, in= t len, int rn, int imm) =20 /* Copy the clean address into a local temp, live across the loop.= */ t0 =3D clean_addr; - clean_addr =3D tcg_temp_local_new_i64(); + clean_addr =3D new_tmp_a64_local(s); tcg_gen_mov_i64(clean_addr, t0); - tcg_temp_free_i64(t0); =20 gen_set_label(loop); =20 @@ -4509,7 +4506,6 @@ static void do_str(DisasContext *s, uint32_t vofs, in= t len, int rn, int imm) } tcg_temp_free_i64(t0); } - tcg_temp_free_i64(clean_addr); } =20 static bool trans_LDR_zri(DisasContext *s, arg_rri *a) --=20 2.25.1