From patchwork Mon Feb 8 12:38:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 378598 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp4948483jah; Mon, 8 Feb 2021 11:08:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVRC9814nM4pLg23xQcGTB3xB5GA2BOPOmPQkTFRurA8MB+AxS2bkxZkw/QS2rfes1E50G X-Received: by 2002:a25:3056:: with SMTP id w83mr26324495ybw.504.1612811321184; Mon, 08 Feb 2021 11:08:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612811321; cv=none; d=google.com; s=arc-20160816; b=l/yfYM6X1rnSWVU99DR09PKZ3lQPvRPQpZLe5vIrgnXhittfwbHLLZZwu0De66IBZH F7txMaNlxAQ62yzp5SF1JTAuJvhm8L4v8cuqirDOV6vVrl3F9TLUlehtlkSunAxYnSyV 8cqJ3Co1Rn48jxbJzWIA3nRYQXNXFWxdpA14gvx4WireFL5DT4Lx750q0+/NWZZmZh5c MpaXKEKNkEjX33bfRXFWJXZ3NhomH0jXFJ84vYNfOxN/tVex1kURCXVLg2ep4WVuWaG3 Nc8AAew3w0+i+IdxTNiKlaTv4KJ6verZO3ZVz+ff+G7caZ31N7VRp0R+r9vtAPVYOomT S2tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=NRda7hohv+ORS/AyN1sYb9iTKw761l7PAGPzaaV6iHY=; b=gj8CuZ5ibBnjefaVxw3v58hQ4DNAeF559Bm3F4Bvbp5jdX6nWgfe9BLI0CSdVLImB6 ZFaeAFLXM6mBwTYvd83SsVsa59ydlhIwuixlzRH+djb3SwfWnpq6YVjhveqZSowdKLNU pWyppkmIi6WVCAcr6Vfn2mTMT7TSWUn4tM7flzHCfSXEWpGs/OOn3hA18fdLq0DUBWVG dkG2RnwfMBmxgJE5SXLI5Hk/vKWC7GFfHrTu0G8wasd1wIT17y6ZGhvPcyw899vulfD3 WYpe45rIE6lvZsP2vpGJcQDDeDpt/Q0+CVVvmeVf/LIqEb2yY/PX9RO1JckzkjzMeBUC xVQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yMc8Tcun; 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=fail (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 e68si18897060ybc.272.2021.02.08.11.08.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Feb 2021 11:08:41 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b=yMc8Tcun; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Bto-0007Cm-Kc for patch@linaro.org; Mon, 08 Feb 2021 14:08:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l95pE-0003fx-EY for qemu-devel@nongnu.org; Mon, 08 Feb 2021 07:39:39 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:42565) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l95oi-0007kk-9g for qemu-devel@nongnu.org; Mon, 08 Feb 2021 07:39:22 -0500 Received: by mail-wr1-x42e.google.com with SMTP id r21so669687wrr.9 for ; Mon, 08 Feb 2021 04:38:44 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=NRda7hohv+ORS/AyN1sYb9iTKw761l7PAGPzaaV6iHY=; b=yMc8TcunZRgGeRtGNmhWgxR56Jp0jPpdaqo8kGLH1Zf/pId7wXkAQqfmMaKcDsKEAJ v4LOeoXqCGwZyyAUPkrjCAJwwYXM5PvYTZzCqCBXwwZ4Wxms1/UzlAO2Nfo8vB5vv7AW tAJLFkUpTKQMquR0m4j020eRejweGzqALAGVoOvMlfyoz7b7JDuL3oWSOswY3fwVXTTu D5QPbQbrifAjoUvZ0HJdt9TPZCmHUuVEJjsWQFOL7XbUVtCj47JPYfpJ16mhza6fJv7i pN+rZs83IjM9KJANvw6NZYZZCBWxnclDRUv0Nni777lcvafPmW+DKZ9mINF6uQ2D/kQb /nDA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=NRda7hohv+ORS/AyN1sYb9iTKw761l7PAGPzaaV6iHY=; b=FD5zX5JZKn8/k2mz5UIIk7UxECqI5gu1CBa5aNFWJrl/jetcOQJcB0J/9YryfoseCw lDeLhRuQO2sTLBkMzeZMekj+J3DklcloDk9sYDc3eD1f+omoS3GUDWvRj2B3vcdWQlsF r4Cw0dxtOywoPzAPzEEK3EayqPo+H6qn8DRRB5LXlb2F9fHZX7XItSioyfDenQ5cedpT ZAbFDAkLuBJ85FYgKYR5mQ8+tigSRGd/fjOipgBRZ/2VYZoDJ/0QZqAYozOAvfBlSLNp NXc6udMq59WmDqRjSYdaTQ4LP9WAJ/+tjQL6MLFWGi8U3EoP3td01/Sq+43gyVpZDAWy N9lQ== X-Gm-Message-State: AOAM533qMjtql+PSl8UFyuAW7ubH0n3/Zl6q1Lx7z8JlpDHzJY8dMq/m vVc/MlitQoRirjMoP/YcKzJjLQ== X-Received: by 2002:a5d:4383:: with SMTP id i3mr19822242wrq.293.1612787923465; Mon, 08 Feb 2021 04:38:43 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k15sm20168078wmj.6.2021.02.08.04.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 04:38:33 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BB9F31FF9A; Mon, 8 Feb 2021 12:38:22 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 11/16] gdbstub: Fix handle_query_xfer_auxv Date: Mon, 8 Feb 2021 12:38:16 +0000 Message-Id: <20210208123821.19818-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210208123821.19818-1-alex.bennee@linaro.org> References: <20210208123821.19818-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.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=unavailable 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: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , qemu-devel@nongnu.org, =?utf-8?q?Phil?= =?utf-8?q?ippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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 == auxv_len, which would result in an empty packet. Fixes: 51c623b0de1 ("gdbstub: add support to Xfer:auxv:read: packet") Signed-off-by: Richard Henderson Signed-off-by: Alex Bennée Message-Id: <20210128201831.534033-1-richard.henderson@linaro.org> Message-Id: <20210202134001.25738-11-alex.bennee@linaro.org> -- 2.20.1 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; 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 = gdbserver_state.c_cpu->opaque; saved_auxv = ts->info->saved_auxv; auxv_len = ts->info->auxv_len; - mem = (const char *)(saved_auxv + offset); - if (offset > auxv_len) { + + if (offset >= auxv_len) { put_packet("E00"); return; } @@ -2269,12 +2268,20 @@ static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx) 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 = auxv_len - offset; + } + + 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); }