From patchwork Sun Mar 3 10:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61B04C5475B for ; Sun, 3 Mar 2024 10:53:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjR7-0002GX-EY; Sun, 03 Mar 2024 05:51:17 -0500 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 1rgjR6-0002G4-52 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:16 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjR4-0001lO-SP for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:15 -0500 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5d81b08d6f2so3343542a12.0 for ; Sun, 03 Mar 2024 02:51:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463073; x=1710067873; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nyTUdQB4Cl6gt8pecVagVZSZXNdna6Waf3JQSWyiOlc=; b=cPbFKGgs5hW3TR5OpxEdHzHfOEwkCxXY8BrGbhuCrSQdgX/EGnrlE0kQxg+6ieMAFi Qr/OYvWYwCQ8AOTbhYAT1zn/ivUtv1azmcQjzDETRf0IQWnn3A8rrbBaQJhK+DyS7lTq CtTSkDuuDoQlDhmM4fY3cYvMYauM9hn90KfZvE8zAB+t35ezIPvH+u/fxYCeiLfdRvVf j/pJLCQ6uOkNEYy998UCYKqYFG0dXk5rBIcPRd71q8GoUGz9RtnI0XcHxRsN2cnFo48G CcNsNeJru7q73ydjNTMEWWW2P3R511W4/LCFIN8S3QWLtDZ2d7jyeVTm4/RsA7E4dNBM Zv8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463073; x=1710067873; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nyTUdQB4Cl6gt8pecVagVZSZXNdna6Waf3JQSWyiOlc=; b=HLIcNJ96X54P2b0lWyvQz6V//2YDh/BnjjSL32XByzGO+XDleDg4o2FihzKNAwQwLF /gga5xlOR81HDGC38oD8tDxp8FQjikPcaDoSF1mh1nyT/8Es7WXC4LvsZ9tQ+zOw3SS0 Is7v6QZbuBfr7EB1j3PBbV2uBCW9K9rrRNjJPF0sW739gxsGfBl1AscMCau7cflvD7e6 Q55o2c+wmhA8ox1f/EyUQxFgkM3kYAwBQj9z9yuZ+IXSy2SEy+22qxFq37bGNsSuch4A JPVrmR5PAUmAUJhfY20e5ZQI2xoizCnzZz6369NSo9NbkbuqgDZSt/EJ/V4Vj9MKD7u6 mOJQ== X-Gm-Message-State: AOJu0YyH+PqAz93QczURnjDQJBlx4aiMHTxyheLK5nwmf6mab2u8SDTF DOpBZlheroU+NVyxS9p4C9DHNfk7fuY9uPnODJM1PjoFTloWWoYxvB9yNVLfoQSrPxOmTpu5SjK k X-Google-Smtp-Source: AGHT+IGLbvF6FQNEyp6HcSPDrwmnb2srrduPn775HPtwW3D5RmtXDbUaT9LtEl+5muFKkrMUUtgj7Q== X-Received: by 2002:a17:902:dac4:b0:1dc:ca43:307 with SMTP id q4-20020a170902dac400b001dcca430307mr9094105plx.60.1709463073355; Sun, 03 Mar 2024 02:51:13 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id k15-20020a170902ba8f00b001dc91b4081dsm6431936pls.271.2024.03.03.02.51.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:13 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:35 +0900 Subject: [PATCH 1/7] contrib/elf2dmp: Always check for PA resolution failure MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-1-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::530; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x530.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Not checking PA resolution failure can result in NULL deference. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/addrspace.c | 46 ++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 6f608a517b1e..980a7aa5f8fb 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -22,7 +22,7 @@ static struct pa_block *pa_space_find_block(struct pa_space *ps, uint64_t pa) return NULL; } -static uint8_t *pa_space_resolve(struct pa_space *ps, uint64_t pa) +static void *pa_space_resolve(struct pa_space *ps, uint64_t pa) { struct pa_block *block = pa_space_find_block(ps, pa); @@ -33,6 +33,19 @@ static uint8_t *pa_space_resolve(struct pa_space *ps, uint64_t pa) return block->addr + (pa - block->paddr); } +static int pa_space_read64(struct pa_space *ps, uint64_t pa, uint64_t *value) +{ + uint64_t *resolved = pa_space_resolve(ps, pa); + + if (!resolved) { + return 1; + } + + *value = *resolved; + + return 0; +} + static void pa_block_align(struct pa_block *b) { uint64_t low_align = ((b->paddr - 1) | ELF2DMP_PAGE_MASK) + 1 - b->paddr; @@ -108,19 +121,20 @@ void va_space_create(struct va_space *vs, struct pa_space *ps, uint64_t dtb) va_space_set_dtb(vs, dtb); } -static uint64_t get_pml4e(struct va_space *vs, uint64_t va) +static int get_pml4e(struct va_space *vs, uint64_t va, uint64_t *value) { uint64_t pa = (vs->dtb & 0xffffffffff000) | ((va & 0xff8000000000) >> 36); - return *(uint64_t *)pa_space_resolve(vs->ps, pa); + return pa_space_read64(vs->ps, pa, value); } -static uint64_t get_pdpi(struct va_space *vs, uint64_t va, uint64_t pml4e) +static int get_pdpi(struct va_space *vs, uint64_t va, uint64_t pml4e, + uint64_t *value) { uint64_t pdpte_paddr = (pml4e & 0xffffffffff000) | ((va & 0x7FC0000000) >> 27); - return *(uint64_t *)pa_space_resolve(vs->ps, pdpte_paddr); + return pa_space_read64(vs->ps, pdpte_paddr, value); } static uint64_t pde_index(uint64_t va) @@ -133,11 +147,12 @@ static uint64_t pdba_base(uint64_t pdpe) return pdpe & 0xFFFFFFFFFF000; } -static uint64_t get_pgd(struct va_space *vs, uint64_t va, uint64_t pdpe) +static int get_pgd(struct va_space *vs, uint64_t va, uint64_t pdpe, + uint64_t *value) { uint64_t pgd_entry = pdba_base(pdpe) + pde_index(va) * 8; - return *(uint64_t *)pa_space_resolve(vs->ps, pgd_entry); + return pa_space_read64(vs->ps, pgd_entry, value); } static uint64_t pte_index(uint64_t va) @@ -150,11 +165,12 @@ static uint64_t ptba_base(uint64_t pde) return pde & 0xFFFFFFFFFF000; } -static uint64_t get_pte(struct va_space *vs, uint64_t va, uint64_t pgd) +static int get_pte(struct va_space *vs, uint64_t va, uint64_t pgd, + uint64_t *value) { uint64_t pgd_val = ptba_base(pgd) + pte_index(va) * 8; - return *(uint64_t *)pa_space_resolve(vs->ps, pgd_val); + return pa_space_read64(vs->ps, pgd_val, value); } static uint64_t get_paddr(uint64_t va, uint64_t pte) @@ -186,13 +202,11 @@ static uint64_t va_space_va2pa(struct va_space *vs, uint64_t va) { uint64_t pml4e, pdpe, pgd, pte; - pml4e = get_pml4e(vs, va); - if (!is_present(pml4e)) { + if (get_pml4e(vs, va, &pml4e) || !is_present(pml4e)) { return INVALID_PA; } - pdpe = get_pdpi(vs, va, pml4e); - if (!is_present(pdpe)) { + if (get_pdpi(vs, va, pml4e, &pdpe) || !is_present(pdpe)) { return INVALID_PA; } @@ -200,8 +214,7 @@ static uint64_t va_space_va2pa(struct va_space *vs, uint64_t va) return get_1GB_paddr(va, pdpe); } - pgd = get_pgd(vs, va, pdpe); - if (!is_present(pgd)) { + if (get_pgd(vs, va, pdpe, &pgd) || !is_present(pgd)) { return INVALID_PA; } @@ -209,8 +222,7 @@ static uint64_t va_space_va2pa(struct va_space *vs, uint64_t va) return get_2MB_paddr(va, pgd); } - pte = get_pte(vs, va, pgd); - if (!is_present(pte)) { + if (get_pte(vs, va, pgd, &pte) || !is_present(pte)) { return INVALID_PA; } From patchwork Sun Mar 3 10:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BB78C48BF6 for ; Sun, 3 Mar 2024 10:52:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRA-0002Gt-1y; Sun, 03 Mar 2024 05:51:20 -0500 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 1rgjR8-0002Gg-Ib for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:18 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjR7-0001mn-I7 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:18 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1dca160163dso35136675ad.3 for ; Sun, 03 Mar 2024 02:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463076; x=1710067876; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MDPpZdzkFCU5J1swCsSX5D8I/lTikuo3763zNkmYNM8=; b=dKvhJnRaQacLN9Iwj/STwIp5LwfCRpb6Hzxq0hLGQ1UlbnSqhA4PiyFj3Jtn5cFqZL GfIGapSJdV/pwdswbUUkLnwX8MSTup12dwzqj5KBQSf97m8SwtSl6enOnMi8ivwjimGR t+gld7Al6wZB/sHCHMjEX7NYliEeUoV63z97FKndHQUbvY9UQCJmKmmg7UK+p9rpl7dX oXDCgTRCIl4joJ6KuPQp72mLjcUpROPTtb5DcPyUePzrInEkxGxJ9NIsScfrdpfeKAR5 xx0bt0Pdjwsn/2lsaVRcEZ7AMWt+kjyewmrlHtT6T524E6tfYiOmeOB27m7kVyvy6TZv 0yKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463076; x=1710067876; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MDPpZdzkFCU5J1swCsSX5D8I/lTikuo3763zNkmYNM8=; b=pXRoFqE9CDydrXIPAm7zQM3eNk8d6UwLfkUw4KeaTZouMj6BAWdMJcHiqEJPHNQ3Ot Cw/766Q3mHUKd8gdMzjDMI7pg/XpCuDKvgVgG75AmjC7KGz7L2eJDaXVYaRmIiMP6Bfd pWTqOq8pDscjrgdYIrSphB0ErETCnhK3Od9J6TZ44A5mpToNGQGLbBmlDUNAbwYrnK1v 7o16mWuubYvUiGZLq+mFbW2nh17m43ZjJbcbOOMvsRyiPVb9GQNJ2LeX5OoOxSCpM3MQ V52BI096hddLQbOVA/ENERyZXOer9yjy/Iz4HRZT8aRTBsU6l/dyzZA6RYgFtXjch+Kp GrDw== X-Gm-Message-State: AOJu0YwDWouQy7yIXBqrjt2vKZZCLTQyEyEdTFXpexGo3x7++ER5NJcN WUwCZ3JeBqMo67w+T60ydeqjOGyge3jcizR4hwi4kHUg1zu12xtc6H4+LnX9gLBLc6MU0wIuxPq I X-Google-Smtp-Source: AGHT+IHVajiJxUowtWrpP3NYpx/+EN/bjBAVRYuyrEDurRGn/xOzYR+hrGPvl2zYLkmq9Y9lx21QXA== X-Received: by 2002:a17:902:e843:b0:1db:9a7d:2e6 with SMTP id t3-20020a170902e84300b001db9a7d02e6mr9807762plg.48.1709463076028; Sun, 03 Mar 2024 02:51:16 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id w1-20020a170902d10100b001dbb14e6feesm6468768plw.189.2024.03.03.02.51.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:15 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:36 +0900 Subject: [PATCH 2/7] contrib/elf2dmp: Always destroy PA space MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-2-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Destroy PA space even if paging base couldn't be found, fixing memory leak. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index cbc38a7c103a..dd686280f981 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -553,7 +553,7 @@ int main(int argc, char *argv[]) if (fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); err = 1; - goto out_elf; + goto out_ps; } printf("CPU #0 IDT is at 0x%016"PRIx64"\n", state->idt.base); From patchwork Sun Mar 3 10:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579720 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7FD1C48BF6 for ; Sun, 3 Mar 2024 10:53:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRD-0002Hj-GX; Sun, 03 Mar 2024 05:51:23 -0500 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 1rgjRB-0002HG-VW for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:22 -0500 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjRA-0001rN-UV for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:21 -0500 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5e4613f2b56so3291781a12.1 for ; Sun, 03 Mar 2024 02:51:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463079; x=1710067879; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8euAnCNzIztjXeyNg7DMouGQMP5MoiXBmM3i2w8JTRU=; b=ZUm6bv9Ule0ReE74AFoPw3lJBh4DV0hIeJxnqJuJxYy26LWAaNpaM9nRCghFIkiMDl PK4AbXV9Cdc9VZFsmzZpkwTe20MIi6XzP5W9ugObW5adg7EsH6ZRm7ZzFwhVjrBjOx4B NICCXWG7bWkZEA3tw6nCT1eFPXv3ZEml40KFWJNCTT0dqy9brmaa4DO4o7DtD6cSa2P2 /E528hlwbIQQD30/WSnA7JuvRcCokfFGTEFnL4WeEVrZMN7/WF5BMcI53dAra+xLsAOW Zqrd+M79KRz9Oy9TU/aHX3Zehbvfkm4+37N2KflYD2WWdCs/c5uI2L68cjQehLol3nCV kJFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463079; x=1710067879; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8euAnCNzIztjXeyNg7DMouGQMP5MoiXBmM3i2w8JTRU=; b=vjX9VBYXXlVG6WOgrSHTZ439CB75vl7clD5W1/0XHsqh8/7i3QcRkkrm0NTzfWsLyP NMWyyqyhApgrrlIr/+gVqrEx7TSj5Y3HQuEYrr6/v7mQRYZsh4AW8rRgach5h0qDl+Uk GD42k8otkeKXxQhzsW+d9l8ptaOHUStOUAZfBPpMm3Ox1V/AmtaErgekXIdVoarGf578 viLjAWQBh1kFQUysErnZYqY++gi9Tj4cC9hZRZSyxb7MTISt3YfDmAVjOIBWV9A6qCGl o0LSkLcQOhpRktx7Hq+OwXGjG+Pg713WweG63puGi91KG6NAAwFoGJIKVGA4mOuKryPn Us1w== X-Gm-Message-State: AOJu0YxINmdAAYSO7Z1IxDyN+ME/yCPYdRbKWrKFJ7nfMZmFOKiSR3ND JvpNJ9lUryZ3KH1fIwTuK5Rfrq29ETi9y95Wi5ue3m5Qf6nd01gKnZ5ssvbLllib1/on9O4u1bS c X-Google-Smtp-Source: AGHT+IEZ3rXPtNTO69XiXPFL/qSa5befnHTK0lTbNn4rLzlPG+lqYGI/QtXFCQoB4Yq+8kZguo9y/w== X-Received: by 2002:a17:902:f681:b0:1dc:84ab:95d with SMTP id l1-20020a170902f68100b001dc84ab095dmr6947426plg.45.1709463079469; Sun, 03 Mar 2024 02:51:19 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id kz16-20020a170902f9d000b001da0a698095sm6456090plb.282.2024.03.03.02.51.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:19 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:37 +0900 Subject: [PATCH 3/7] contrib/elf2dmp: Ensure segment fits in file MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-3-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::535; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This makes elf2dmp more robust against corrupted inputs. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/addrspace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 980a7aa5f8fb..d546a400dfda 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -88,11 +88,12 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf) ps->block = g_new(struct pa_block, ps->block_nr); for (i = 0; i < phdr_nr; i++) { - if (phdr[i].p_type == PT_LOAD) { + if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset < qemu_elf->size) { ps->block[block_i] = (struct pa_block) { .addr = (uint8_t *)qemu_elf->map + phdr[i].p_offset, .paddr = phdr[i].p_paddr, - .size = phdr[i].p_filesz, + .size = MIN(phdr[i].p_filesz, + qemu_elf->size - phdr[i].p_offset), }; pa_block_align(&ps->block[block_i]); block_i = ps->block[block_i].size ? (block_i + 1) : block_i; From patchwork Sun Mar 3 10:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E972C48BF6 for ; Sun, 3 Mar 2024 10:52:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRG-0002I2-1q; Sun, 03 Mar 2024 05:51:26 -0500 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 1rgjRE-0002Hp-Hn for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:24 -0500 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjRD-0001vc-ID for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:24 -0500 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso3213592a12.3 for ; Sun, 03 Mar 2024 02:51:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463082; x=1710067882; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ot05ideaXjHDt/XtCs48E+XgUuov6SHY9sSACugHv/8=; b=rTRGAaMtiI4Z/8gWecRIiW0SCnN2fqQX4sA59lp6Yi8UqRvMFynz3rQvje2OANignS eyjHHQ6tn9VAFCXxm4QlnUeRKRFi8bT9CZCfEQ0oxbVDELv76HesGMCTmAunn98eP1z/ lK+aSvA1G2kUrwx1wJqTVyg9dUjUsYSyT9Z30zst2BcmSM8rtT5VpVpCNoqAOQMnNUSt NoAixkgvTp57Vzjc+gAog/xkt2cm6FHXcz1ypLPRl006QIujQOLYOrDDgYSFzDaqAqPG JMD68v0qMuAzV+GtK9p6tncQVo5YueXu/3ES2HoBtgn2BP7gruwgH7A6BmuvZ4rhlqxF zoLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463082; x=1710067882; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ot05ideaXjHDt/XtCs48E+XgUuov6SHY9sSACugHv/8=; b=DTfyaL4ukvLoO84nmdyVUfR6HRNX5QFUAamyjqzC9bKyihu1rNm8YR0fUqanmyj27b w4Gk45+wXPye3505mgtrnp9PZe9g4GcF/iXDrVfDj3QKhu8RZT4Hvgo7n/vVmbVYX+bb SIsusl4ipLGGRusDd1OEZ69rk1SkeGmgxEG+S+FnHuRD/SjMgnnnZgt0THGTWFMCUnqf vCPCpk/pBMXRM1JfOOVvNlydb55GOOgex9nAPVPwJ7nVPKdyJZivrnMusMZ0vwLReCQm wxABG19YaTaiy4U1Dr2VOjcglK8Y72eWQK68x7P7c0v7YN4ZvFAjfE1Y3g3ugQiLVdgD WCOg== X-Gm-Message-State: AOJu0Yzq/658a1m9GzSryshuFQXcLXqU8bLezqDqC86SsDqZ7xMhnqQp b7TYBCQ/Z60CTDQ7Hq/35unasUogd1EPkfYHkClkDbT7MLDKlK4yq/89SbVmmCHaSZndG4Dh3b2 e X-Google-Smtp-Source: AGHT+IHPLsrD8aWFPj7I2exnN8z+GxwL27lj8jZ69zrPuabL64JztbfLxsWydaTz1Sp/aJ/gi6agYg== X-Received: by 2002:a17:902:c204:b0:1dc:f913:797c with SMTP id 4-20020a170902c20400b001dcf913797cmr4779179pll.51.1709463082191; Sun, 03 Mar 2024 02:51:22 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id u11-20020a170903124b00b001dc01efaec2sm6435731plh.168.2024.03.03.02.51.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:21 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:38 +0900 Subject: [PATCH 4/7] contrib/elf2dmp: Use lduw_le_p() to read PDB MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-4-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::532; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This resolved UBSan warnings. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/pdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index 40991f5f4c34..2541234205c3 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -19,6 +19,7 @@ */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "pdb.h" #include "err.h" @@ -187,7 +188,7 @@ static int pdb_init_symbols(struct pdb_reader *r) r->symbols = symbols; - r->segments = *(uint16_t *)((const char *)symbols + sizeof(PDB_SYMBOLS) + + r->segments = lduw_le_p((const char *)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size + symbols->offset_size + symbols->hash_size + symbols->srcmodule_size + symbols->pdbimport_size + symbols->unknown2_size + From patchwork Sun Mar 3 10:50:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91CE5C48BF6 for ; Sun, 3 Mar 2024 10:52:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRI-0002Iu-NI; Sun, 03 Mar 2024 05:51:28 -0500 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 1rgjRH-0002IP-DN for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:27 -0500 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjRG-0001ym-DZ for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:27 -0500 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6e4c62b6406so1366825a34.0 for ; Sun, 03 Mar 2024 02:51:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463085; x=1710067885; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nCsWk0WGiVM2x8kzQW2DXQXp4GeFwvjE8Te/kDy8WeQ=; b=YBFmxBStmyc+fW8k41hDt/arp+jjpweyFlmEkA0TgiNrv4vGwPqRF7wnY7V9MCzb9J xkugaj+gRVMdsL0oMwYJ4RJZU0m1besD7isM+7Vn8WgM6X7974xLXNavujj5OHoJkN8k UcBrWe3ZXH8UDBiZsbg7Eu6GBjo9zRDJPtoVLnRJXsYL9si8zYVsKUutjM4QaadkRIQm w7WOF8ixGoxaKYDJr8Cu5XiGQjfR84hAbGlvA0t4TfrGY1/KCE//ogap9rQ6lKWjIVIX nSFsH0qGOsD4ljqOBFvK+8KZpWDGpChpcBZjF9fwvlQbK+5IlAF9NS+fMnlYpjV9D6s8 Z20A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463085; x=1710067885; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nCsWk0WGiVM2x8kzQW2DXQXp4GeFwvjE8Te/kDy8WeQ=; b=CCaGzzE0t6fvM/MG2Gm9/TzU1VZdw15fXpF7hLAK040ayNejEYRdpvW8UecCdoYPzj 7Evgp+ZiqChF1YUUlI2kEQUICAEcC+xCxeRBIDyOwijY62g42CtjH5ca180YAvGpjbiu gcn6v/b68jIpjYUwbd7BLvwDGbCulRb65o1AoylTaOmIPO+xr6X8NLiKaj5uHBz3Qdq8 3dLMBe/pHZ0PaEwlhZrCPMs5ELcu37MElWjmNUNP4LO6d14PKSUCHkk+6avMh2ENoWF2 DqjRC1Fnp33ml5M9ioEYu22fbjnmrX83QQXRfsUf6g04SJZXZa0N4gZwxlia/KchFKiU IT1g== X-Gm-Message-State: AOJu0YxTQtK+dQQ71S4lgJrpfU9pHjCuRuY1vH4vY4if/ateeTlS9K0w Qf6xR+4Z0DF3iDAiB0FDoM5m/Jq3mh1aHKiaXsTW7MZ87uRq9ksdY7O1NQ2C4J6486Ph3TTm+E5 g X-Google-Smtp-Source: AGHT+IHDupLpwhjK1Rvgy5zwR+avyLwV6+hJxnijjgEQJjTWaRDMSVkpWH5eCXXQhfvWiviX9MtvBg== X-Received: by 2002:a54:460a:0:b0:3c1:da6b:b3e0 with SMTP id p10-20020a54460a000000b003c1da6bb3e0mr4410045oip.39.1709463085067; Sun, 03 Mar 2024 02:51:25 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id n2-20020a170902d2c200b001dc2d1bd4d6sm6478736plc.77.2024.03.03.02.51.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:24 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:39 +0900 Subject: [PATCH 5/7] contrib/elf2dmp: Use rol64() to decode MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-5-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::334; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x334.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org rol64() is roubust against too large shift values and fixes UBSan warnings. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index dd686280f981..432f8629f321 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -6,6 +6,7 @@ */ #include "qemu/osdep.h" +#include "qemu/bitops.h" #include "err.h" #include "addrspace.h" @@ -47,11 +48,6 @@ static const uint64_t SharedUserData = 0xfffff78000000000; s ? printf(#s" = 0x%016"PRIx64"\n", s) :\ eprintf("Failed to resolve "#s"\n"), s) -static uint64_t rol(uint64_t x, uint64_t y) -{ - return (x << y) | (x >> (64 - y)); -} - /* * Decoding algorithm can be found in Volatility project */ @@ -64,7 +60,7 @@ static void kdbg_decode(uint64_t *dst, uint64_t *src, size_t size, uint64_t block; block = src[i]; - block = rol(block ^ kwn, (uint8_t)kwn); + block = rol64(block ^ kwn, kwn); block = __builtin_bswap64(block ^ kdbe) ^ kwa; dst[i] = block; } From patchwork Sun Mar 3 10:50:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9AB3FC48BF6 for ; Sun, 3 Mar 2024 10:52:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRZ-0002Mi-Mo; Sun, 03 Mar 2024 05:51:45 -0500 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 1rgjRY-0002MX-H5 for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:44 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjRJ-0001yy-2T for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:44 -0500 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5cddfe0cb64so2608113a12.0 for ; Sun, 03 Mar 2024 02:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463088; x=1710067888; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ItPC9lAeHcpFUfTU9c6xUSLUEP8u71tkDj/Uzspnk/A=; b=WSa1u5dpR4aT63L6lq6kSm3K46aBpx3G7zSak+RGE7Bd5Zpqa86d3B/cGBszjee5HX M55PyXbV6sOT5iKMoOxeFsZ0dQsLeEydA/5bFTohXuPHu2wONWqNkz6nbrtNgNZJbysb oYrc2QOcRFnH425+OxjA9rhxAs0mdTKf8PbRsTDNY3XtbkpfGcNiuEtYqcfORUvhyoiv xaqwW6S1TVXW4MxEKIax0HNtPqjj3aXCu1uOkNUL1JLYOiBun/5XNJI360S7lNuhsbNB 2AEtxPpq74JQrwTnD/O4qlyiffUGbogvzheHWyhwa+FMJkaoAMvb2Qy+O0VlUS8d9/zg HzqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463088; x=1710067888; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ItPC9lAeHcpFUfTU9c6xUSLUEP8u71tkDj/Uzspnk/A=; b=SMCX2FYxvrVaj/sehw6fyhz8FCh1KJuwXYuOx8scMnzmLnB9ivfhY65ZTMtZs0ewip eCRyPkBuC6ATpsNT+cMi+s25i9dl7qQaBga4jSXGEI6wSV1n77WKtSFRludvTgGimPOs E1M07o564cpHREL9YODxu3OBumNiIPglCwtIFpJcckhXFyd4ssMLaET0KfHTTby34bTU DEdaeIX9gKQ2UalvO9iyjqgFAnONmbLNP/6iZ8YQ8Zi0TBk07OJsZgOJw95zM70uxfV6 Lhx1OMoLnxzvLpWUAfmxTlC5QfW3syL7iPecBNpRC+OjUKc3SgniaKR5VsMKWMf0pVqG rkmw== X-Gm-Message-State: AOJu0Yy1LzHOU742SfiJomHyWS2GLUCD88WOl9sy+IEXnd9XP0h7Bpbt vHsOyq8O8xwwwyY88Nip0eLsBs4PjzYjA/arzOewfZdbEzRto4PFk+XP9cqRZUh3XtVZdQYf/6S i X-Google-Smtp-Source: AGHT+IFC3GSWO77KFoKsE5qQ3U/0awI71A/bNluNpt6+9YHligzjb40Lr5A+1BCyiEfRysXy7N6WXQ== X-Received: by 2002:a17:903:124a:b0:1dc:63b2:7c2e with SMTP id u10-20020a170903124a00b001dc63b27c2emr7382395plh.31.1709463087802; Sun, 03 Mar 2024 02:51:27 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id t18-20020a170902d21200b001dca6d1d574sm6425979ply.302.2024.03.03.02.51.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:27 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:40 +0900 Subject: [PATCH 6/7] contrib/elf2dmp: Continue even contexts are lacking MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-6-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::52a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Contexts of some CPUs may be lacking or corrupted due to premature boot, but the output may still contain valuable information of other CPUs and memory. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 432f8629f321..33066310b9fa 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -332,7 +332,7 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, return 0; } -static int fill_context(KDDEBUGGER_DATA64 *kdbg, +static void fill_context(KDDEBUGGER_DATA64 *kdbg, struct va_space *vs, QEMU_Elf *qe) { int i; @@ -346,7 +346,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, &Prcb, sizeof(Prcb), 0)) { eprintf("Failed to read CPU #%d PRCB location\n", i); - return 1; + continue; } if (!Prcb) { @@ -357,7 +357,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, if (va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, &Context, sizeof(Context), 0)) { eprintf("Failed to read CPU #%d ContextFrame location\n", i); - return 1; + continue; } printf("Filling context for CPU #%d...\n", i); @@ -365,11 +365,9 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, if (va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { eprintf("Failed to fill CPU #%d context\n", i); - return 1; + continue; } } - - return 0; } static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, @@ -624,10 +622,7 @@ int main(int argc, char *argv[]) goto out_kdbg; } - if (fill_context(kdbg, &vs, &qemu_elf)) { - err = 1; - goto out_kdbg; - } + fill_context(kdbg, &vs, &qemu_elf); if (write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); From patchwork Sun Mar 3 10:50:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13579722 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3CA2C5475B for ; Sun, 3 Mar 2024 10:53:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRQ-0002Jo-B0; Sun, 03 Mar 2024 05:51:36 -0500 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 1rgjRO-0002Ja-6Z for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:34 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjRL-0001zF-TF for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:33 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6da9c834646so3222889b3a.3 for ; Sun, 03 Mar 2024 02:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463090; x=1710067890; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=T3tYaNcvH121evad5hrC2hPT8ahKSlk1yp9xd2sfeno=; b=PtWPUXyVZ8KicNSydMn60VlxGpilarQH19MPnAGdovuw8LND1B0CP1K5RG6xkIUQZx NV7GdMsG/x5XzkNkZG12sx3s8mO+rKW0zW1MI2Hddn1xfYDizXCugFU19Wfa1uDz5iF2 ZQiwFpPqgM5uoj+vv2PzWfDWhzmocKbyHnJAfYGxSf92ML5hfibctTNF1WoHo++r38zL /cl+OOq+P8+uhMCi/LLujkBVfsjURlrSmwFUkNMds9wJpm+WGFLh1V6AOlqPyLqPAN17 /py+369lO4oNi2UFOS8DCLsIWMmAbrVZ4iXqoiMkGfN8sGkq6ZYgl8XUkmAsGKPtTolZ k9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463090; x=1710067890; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T3tYaNcvH121evad5hrC2hPT8ahKSlk1yp9xd2sfeno=; b=qgehhb8Krstx8PShmiDfIusmtuKaSk4TKQDnzzvPyPtr3MXzs/wG4PSD0M+rZgFxpD wLIHTFe5YCzJbQTVjaNq3xJjHRmLiS3BMDa51DTBZ1OkS/uwK+yg96FSt24i4YRN7VsB SJ1Hcd1rhGZIlQ+kCBhXqplv71NtIdZiZE+qTvc6GMULlVS24sO1Ap3GLaUIoZGH0scz nG+/VcfB9wSQsIzGExqwmiz3V53TvVUg5RpEUDyBylrqew0BVUVrPH+IboMDeJ/45nKC FlqPWGyD1pXKC9tt6an67TM+PVgkzjlbnMBPF6jglYCRlQhP2GQcgGhsJM1aE2puREGg 48kg== X-Gm-Message-State: AOJu0YxekKXehFtSXCe09DybOVQAv1j6l0cO0jbUeHvOzypyiNIJTs2G ldd4fAk9J8BYc1UDnHgii/Vna+Zfewem9xTKr/trtN+oNgwo6r5uE66eMHa5m8xV9JhMmBN+vzM K X-Google-Smtp-Source: AGHT+IFHl97K5u4+NKXu6IsXY15KLt9NxE5yymLidOc2F1+X8vi9Ik4YpOiVMpWk7MOi1xzqAo5ZCA== X-Received: by 2002:a05:6a20:3c8d:b0:19e:67b0:9ac6 with SMTP id b13-20020a056a203c8d00b0019e67b09ac6mr8665647pzj.1.1709463090636; Sun, 03 Mar 2024 02:51:30 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id sl6-20020a17090b2e0600b0029aaabcb82asm8084315pjb.10.2024.03.03.02.51.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:30 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:41 +0900 Subject: [PATCH 7/7] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer MIME-Version: 1.0 Message-Id: <20240303-elf2dmp-v1-7-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 65dfdc9677e4..d25403f3709b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3583,6 +3583,7 @@ F: util/iova-tree.c elf2dmp M: Viktor Prutyanov +R: Akihiko Odaki S: Maintained F: contrib/elf2dmp/