From nobody Tue May 21 05:33:03 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=1611865300; cv=none; d=zohomail.com; s=zohoarc; b=k5Bj/f3zZJd7u6XoZMvSXE8E9z//93jx4wYYeboZmT4dHqt4SsmgufJEVGEHjIk9RmiJKeR/0c9cMU7MwGbL9GYA33cNz9Y8YspBNk390pEiHV52aVRnOU2+5nALFHZkG5ExnLXXav2en+9nsOvQD+ke/PBEyxZ28EUOQbPlS2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611865300; 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=JwPj5CUJWa8K3MHBEU/KHRN6iVPgI6G5msCTjVKG/1k=; b=k6TN0hR6n1E5RV7Us7Cz9L/8yB7MNn9tB2rSXEHMcZakZFCHPCWi/qj+HR9NtzYQrtyEaKw8arE0vuiotQby55ZF6vZ8epTYFlFvYKCazFoHqm+Xi+3JwW2JmlhNJzeaF/DnLDTSbc2R+QFL0xrDJWkW0RE6dzxUeWhmtEBFnPI= 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 1611865300554712.0730618778207; Thu, 28 Jan 2021 12:21:40 -0800 (PST) Received: from localhost ([::1]:42836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5DnP-0002FV-FK for importer@patchew.org; Thu, 28 Jan 2021 15:21:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5DkX-0008Mj-Iw for qemu-devel@nongnu.org; Thu, 28 Jan 2021 15:18:41 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:39892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5DkS-00041Q-Bt for qemu-devel@nongnu.org; Thu, 28 Jan 2021 15:18:41 -0500 Received: by mail-pl1-x629.google.com with SMTP id b17so3983613plz.6 for ; Thu, 28 Jan 2021 12:18:35 -0800 (PST) Received: from localhost.localdomain (cpe-66-27-222-29.hawaii.res.rr.com. [66.27.222.29]) by smtp.gmail.com with ESMTPSA id z2sm6819299pgl.49.2021.01.28.12.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jan 2021 12:18:33 -0800 (PST) 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=JwPj5CUJWa8K3MHBEU/KHRN6iVPgI6G5msCTjVKG/1k=; b=Vf39r2hOMC0mHp7mjpnjQSFeCrN3MieEak1eBTb0wVeE9shchRku30OklUsg4+dREN j7f04GEV7o716RzmAgck3Z4/z+rTuJFgblMYasyVpqqNqVboYIOVIrcHzTcI/Ri4PfhD JHXG5LhyjS+1U65sq0I4xop3LYSyEE1AWIu4d7cpjxk0x8IRAUOKANJ+sp74CDljM6rs k/snZIlGZvroE8RtjTHbMBrGphwYEwNPmmIZZ2dpIq6+4lmbpHZH3xWSQyCqe9rPYhcp ZHcnWOijN91Pdu7a1k0CknIFp2m+GKwTlxRoopIO9Br4oG9H3tHPqBTFKcIDakWKYFuv UKhA== 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=JwPj5CUJWa8K3MHBEU/KHRN6iVPgI6G5msCTjVKG/1k=; b=A/kZO8/ZhdNnYVgduzXMExDN1gX0PUi1kUyPopLFYhsbygwdRT/VHK4Hy+dnYNqU5S qkn/SSKHCZAwaheY5w+56zs5XNSDPv7HYydjd37vBIMXXiLv17+7pRw98BT0+IZ2EXR5 tkV359/vKme7AXzoFwzTh/jMamTMXjzaWZAt9F8tqL+2+MAzX3pSf3xN1nm1SpXUBrx/ jA8virkNb0yJUKiJ10ZBN5DR9Z/7OleEUVEnXTBXjhl1qKCVRz+3SPhMAawh9ztoAegZ 6U44imJvJfL5FlPASoeVHGdJsayIs0VerDH+GHVB3gY9v58BH/7xRzLzd9gGJhhSWVlm Nyew== X-Gm-Message-State: AOAM533a5TSXsGYJQlSmEZUy+M2iwjYNh+VXmgREEMd2l0aTlVEbJIYP oliADCRkklD7pnmmvs+Q6EEy1WEMdCSrwYOv X-Google-Smtp-Source: ABdhPJw9euvRpK0BikmIEiLYIqbRcpobq6j7nNYgJdhu1Zb9S+6Z5j9X0G+wfN1yMd4/qB1ZajuNkg== X-Received: by 2002:a17:902:740a:b029:df:cf3a:72ff with SMTP id g10-20020a170902740ab02900dfcf3a72ffmr1122716pll.12.1611865114717; Thu, 28 Jan 2021 12:18:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] gdbstub: Fix handle_query_xfer_auxv Date: Thu, 28 Jan 2021 10:18:31 -1000 Message-Id: <20210128201831.534033-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::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no 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: alex.bennee@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 main problem was that we were treating a guest address as a host address with a mere cast. Use the correct interface for accessing guest memory. Do not allow offset =3D=3D auxv_len, which would result in an empty packet. Fixes: 51c623b0de1 ("gdbstub: add support to Xfer:auxv:read: packet") Signed-off-by: Richard Henderson --- Fixes a number of check-tcg failures, which are transformed from proper failures to "SKIP: PC not set" by the test harness (bug?). But the qemu executable has in fact crashed. I'm embarrased to note that I reviewed the original patch, and should have noticed this. r~ --- gdbstub.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index c7ca7e9f88..759bb00bcf 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2245,7 +2245,6 @@ static void handle_query_xfer_auxv(GdbCmdContext *gdb= _ctx, void *user_ctx) { TaskState *ts; unsigned long offset, len, saved_auxv, auxv_len; - const char *mem; =20 if (gdb_ctx->num_params < 2) { put_packet("E22"); @@ -2257,8 +2256,8 @@ static void handle_query_xfer_auxv(GdbCmdContext *gdb= _ctx, void *user_ctx) ts =3D gdbserver_state.c_cpu->opaque; saved_auxv =3D ts->info->saved_auxv; auxv_len =3D ts->info->auxv_len; - mem =3D (const char *)(saved_auxv + offset); - if (offset > auxv_len) { + + if (offset >=3D auxv_len) { put_packet("E00"); return; } @@ -2269,12 +2268,20 @@ static void handle_query_xfer_auxv(GdbCmdContext *g= db_ctx, void *user_ctx) =20 if (len < auxv_len - offset) { g_string_assign(gdbserver_state.str_buf, "m"); - memtox(gdbserver_state.str_buf, mem, len); } else { g_string_assign(gdbserver_state.str_buf, "l"); - memtox(gdbserver_state.str_buf, mem, auxv_len - offset); + len =3D auxv_len - offset; } =20 + g_byte_array_set_size(gdbserver_state.mem_buf, len); + if (target_memory_rw_debug(gdbserver_state.g_cpu, saved_auxv + offset, + gdbserver_state.mem_buf->data, len, false))= { + put_packet("E14"); + return; + } + + memtox(gdbserver_state.str_buf, + (const char *)gdbserver_state.mem_buf->data, len); put_packet_binary(gdbserver_state.str_buf->str, gdbserver_state.str_buf->len, true); } --=20 2.25.1