From nobody Tue Nov 26 06:58:52 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=1709059750; cv=none; d=zohomail.com; s=zohoarc; b=WVME80A1w5DYUtv3+6trHcPTzkDI+/VukceCojShHUdOXPmBbbWs9W2V9TATucu5CIFlf4E1SJ72s5hEx70SvOzgdSQG3OaXPBJhKYompnsKQuNvcuw1yl6QaBxBqlh+jQ0greE7G4wdjPcUTKqxxGnQUSbcgwIxAn4j0fJcvc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059750; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jYBkGoMMC9wjPymAcLzdiqwt32NykwjmDLE/jmy3uYA=; b=ZzV7MZP9mfYcMkc6Gd4OrLEx0RlnHniJHNO4DK/zHnyNBAuBdU2zQ7bQF0Fqe+UNctKs+O5wQnE+rdW/CnBu5OeZjk8Gk3H/fXMOzm4bhxt50uOj8TJG4sYh+Bun9anqp/XVRT0TDKhwPGbXkpGTCYLE0Gt8Zxjhe4+IuqD5wRY= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059750494562.1180479940275; Tue, 27 Feb 2024 10:49:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VO-0006Ua-Ih; Tue, 27 Feb 2024 13:48:42 -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 1rf2VN-0006U2-5h for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:41 -0500 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VL-0001ST-JZ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:40 -0500 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6e4957ff05cso1621046a34.2 for ; Tue, 27 Feb 2024 10:48:39 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059718; x=1709664518; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jYBkGoMMC9wjPymAcLzdiqwt32NykwjmDLE/jmy3uYA=; b=PTWOgijnVwgQfa5nMUkRjVR5K3R0he76rfrErF9KisHjaKTDaJFh0Z42IDGsZab/8M BVuQaio33mtUA9L2XCBiqJePIWohU8mGEmzK+Sm77RCFuexvrJmbfh5tg1MwJWviOU9W k1XlgdZQbJ5/X7Sn1CZLHbc3/x0bXVwzaOkAEEj5UGRtDDQHskp+t57GaMJUMyCRqAhv j4i0r8zHJu9hb6ljI3+LcQPynMMfk7mqmwSpLj8/xItp69QK/ZjVQFfJcvl320KU4q01 RBLFAfyQZsTwtGkc+JJJs0bhJFxxZTvshPwlCvJ66qLstYjC022lu8cp5GkAGUoTA0jP d30w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059718; x=1709664518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jYBkGoMMC9wjPymAcLzdiqwt32NykwjmDLE/jmy3uYA=; b=NMqiNn9gC5p7+XMhCyXqd2KsL8XekO4/d9ya1k+0SJwjSLrxIbY80ft2fi0rEUiSJN fxF8ojgPZw0bgqa6QcD/SkGj1AOfJeB82TW0Fo93jsB07JXj7u9kWvkeQ6KhWplm4Mc6 sk245Dmr7biXOlDMuy00HL+yh5JF5RkQLx7UN9njatm/bUQgYNZFj0zldHskV22xIN/7 CJv4FSxoYjDrgrD8Cr0mdy49qTnc8zjUQuY/cx+YZDDWg3XRtjvTCJ4ztFsTizO0qOOV //0MnW5xBDgtkiODX2QToMds5RWKkPWXDmAH5PJl6SgiQ6I157tGkPSmrMFzXMv2bweV 35lQ== X-Gm-Message-State: AOJu0YyZo3sAnL6lT9hqFhNY5NdA2QJvayKg+rzde6j5m7D7WrvzLEeR irizTmGkV35R9LESl7VkyVXH1SumdCqF9b8Pf4yW12su2KZaFia7osksaQ53Q98VKDFkzAXiN/v j X-Google-Smtp-Source: AGHT+IFiH9Zm7aK5ryGMl33mU4PJvdSIBmUzqUo9c0/mSBWARMXyCltNiDwnNSdBUuRLo6k3f4fyog== X-Received: by 2002:a05:6830:1390:b0:6e4:7a7b:700b with SMTP id d16-20020a056830139000b006e47a7b700bmr10732280otq.14.1709059718356; Tue, 27 Feb 2024 10:48:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 01/14] linux-user/elfload: Disable core dump if getrlimit fails Date: Tue, 27 Feb 2024 08:48:20 -1000 Message-Id: <20240227184833.193836-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::333; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x333.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059751820100005 Content-Type: text/plain; charset="utf-8" Do not dump core at all if getrlimit fails; this ensures that dumpsize is valid throughout the function, not just for the initial test vs rlim_cur. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e --- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b8eef893d0..fb47fe39c9 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4673,7 +4673,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) return 0; } =20 - if (getrlimit(RLIMIT_CORE, &dumpsize) =3D=3D 0 && dumpsize.rlim_cur = =3D=3D 0) { + if (getrlimit(RLIMIT_CORE, &dumpsize) < 0 || dumpsize.rlim_cur =3D=3D = 0) { return 0; } =20 --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059814; cv=none; d=zohomail.com; s=zohoarc; b=Zcxt/QZv8CY0q+SH326Lk6WuBWqUE3rfihA7tlcUNiyiYYKsjJu4KXrHodl4991QWar64vDTA4ReCjepT9+jGrFe95rs5KnpPWF5wKGbjZZemgzAscbP9qoF07ymQmdjVR5DvpQ8AfLET2e7NjkZzNsavJq64cWsC+I1n0nxFiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059814; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MxsvOR0/a5Fiag9KhwB5MSJsMkkn1D/1jCzIg2T94l4=; b=TQFtivwkphAsbw3SwpBTVAedHV++FWX0yohyjncB98rX3F9DQvJwv6XKR5Y2xIMihM+s92St5HMAvPY7+MK2vAzZ1S4qHVPmSui2xCFH2xfyixZQaCqTNK0w5dlVLCBvFxfSOHtH+bU3+P1yaXoXlFjfDxUQuTu/Rfb4YFgW2yE= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059814794523.6049656531326; Tue, 27 Feb 2024 10:50:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VQ-0006VY-4F; Tue, 27 Feb 2024 13:48:44 -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 1rf2VO-0006UZ-EL for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:42 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VM-0001Sg-S5 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:42 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e4670921a4so2609175b3a.0 for ; Tue, 27 Feb 2024 10:48:40 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059719; x=1709664519; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MxsvOR0/a5Fiag9KhwB5MSJsMkkn1D/1jCzIg2T94l4=; b=J65mZqXGCpH6CmPVl5mSGPssxRy4nwkWCiLpbJr547qkUFc6CEXd+sUxbB+KyZfdd3 dRqxp9VjFwkWajQfO/oprV8xJ6nwj25Tl8a6GKDqX62N1nVnYNC3yyhuoW0wug6+zPM4 qj3AHck2CLX7MjLF+d+tvBrRW6864cSBT6htUANIXigzVfMU2Jik62EpIRwM/hKdm/7l d46jr+ywRKgiFG8NNdxv5WRLGmUgIr5Mym3it+RZPKK97R0jHCX2FmfLcIDEylseMRRB RbRRH6Lj11TWIwR7ImfZX8xYB67yypiEtepN5rijz8F9gbpbDKraT6uKg99VMNpageVs Niiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059719; x=1709664519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MxsvOR0/a5Fiag9KhwB5MSJsMkkn1D/1jCzIg2T94l4=; b=Duot5BLtyZyvrqHbp7/+EWZmgIRPMDfTv+xOaG+Qkci71V6XSLNxJksx73TH52jeeV 1u1P8ubxfT8oY3CHcu7sTDiynNHcjxShA8B+xJHojOMWfNUyvSs/HskuFLqV02L6Y4Ih p/uVwD7NqAp2oeUYEGmBU6QmdeiVVZAGB3yiy57ew50JKMmB92ikUi4eURqRXefPuP8R t6vI32xlvwXriaLGZyNcbEQlJucGq3rurWTg1S31gnIE/WRlMJNRKt/b6XM7P80pVWk2 DyO1fRxBZ7jkodfTNMy8ftgIF64JH3KLehxKvKDXUWbqfgJfB+glQuCEfYnpm9jDcTDU sv5Q== X-Gm-Message-State: AOJu0YxgpdgEw4NO0MLoW+/hRrS/MgoJXde76sTbABd+kzJF2LcdNYYI N09O+/v5peLCs1gaC1QLWdtA7DS3MrMI9wU2b1CjUv90/QMyLVzQd6j1KSFRuAbyhiBSy2HRkPT h X-Google-Smtp-Source: AGHT+IG3HA4sPOG7A9GguxkXcS/EGAtKEqjqVf6uu/rYdVPHrLQRxDlRwxtHqpiBxoRyawSC1zKtqw== X-Received: by 2002:a05:6a00:4fd5:b0:6e5:109b:959 with SMTP id le21-20020a056a004fd500b006e5109b0959mr8672528pfb.25.1709059719552; Tue, 27 Feb 2024 10:48:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 02/14] linux-user/elfload: Merge init_note_info and fill_note_info Date: Tue, 27 Feb 2024 08:48:21 -1000 Message-Id: <20240227184833.193836-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059815182100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e --- linux-user/elfload.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fb47fe39c9..7b3a2c20f2 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4514,16 +4514,6 @@ static void fill_thread_info(struct elf_note_info *i= nfo, const CPUArchState *env info->notes_size +=3D note_size(&ets->notes[0]); } =20 -static void init_note_info(struct elf_note_info *info) -{ - /* Initialize the elf_note_info structure so that it is at - * least safe to call free_note_info() on it. Must be - * called before calling fill_note_info(). - */ - memset(info, 0, sizeof (*info)); - QTAILQ_INIT(&info->thread_list); -} - static int fill_note_info(struct elf_note_info *info, long signr, const CPUArchState *env) { @@ -4532,6 +4522,9 @@ static int fill_note_info(struct elf_note_info *info, TaskState *ts =3D (TaskState *)cpu->opaque; int i; =20 + memset(info, 0, sizeof (*info)); + QTAILQ_INIT(&info->thread_list); + info->notes =3D g_new0(struct memelfnote, NUMNOTES); if (info->notes =3D=3D NULL) return (-ENOMEM); @@ -4665,8 +4658,6 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) int segs =3D 0; int fd =3D -1; =20 - init_note_info(&info); - errno =3D 0; =20 if (prctl(PR_GET_DUMPABLE) =3D=3D 0) { --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059896; cv=none; d=zohomail.com; s=zohoarc; b=GAN3XscrFKO5UQw2HcHtCR52rgd2zByvvIJeprdvU8EheMROBUWHdI1ojXDQbPahbwxFhCpM6+Ev4LVtZ68INmyQLLHj/7lvImfB5URBFbwIu48t0EX7lqUI+uS2QQdO3StvmXIcZvvZiLQWWdy8lozCpVrSpNpT07Ui5nlEt50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059896; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=LHOp4zkBgk0kHi76x5Ikm9qOnDGO3FBoO5Ufwy66xpwe+8ffmNxkn0JvF5be9GXmfl2RG6D9AeuIrkhDqr6zwg25zsMNlaUNx7D4HTLOFQPim2ObCB5X442YkwRHJ+HeDIf1jkPJxR+IDwSyqjxmxS4tAJO2yd45iKPyOM0+T5k= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059896274980.120097457609; Tue, 27 Feb 2024 10:51:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VR-0006WC-Jy; Tue, 27 Feb 2024 13:48: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 1rf2VQ-0006VZ-4p for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:44 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VO-0001T1-Dm for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:43 -0500 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6e4ca46ab04so2862653b3a.3 for ; Tue, 27 Feb 2024 10:48:42 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059721; x=1709664521; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=tZKCD9EcLCeJpd6jK0rsk/Llmj4h6oZbe6kdgW7K+BDGg1KAGtyznYuZKjs9LMVTtT UOFi/z/ceoQfLg1S4U+JlnV18R6WHmhflANj1sRjUNQXsHmhvWX648AKT45ty9KrupLJ hG+O9SiHsWUxpbZes47/CTPr2rv34kjB5YSFMguxEQZGkLf8bl5AAZm0Lh47Pfp9w8xh g2/h53CBS6pP+fEG7Hf7DLGNGH0KlDyhWSHRv1hXuXvRfVueOHe8yaEdSGRFecMPB5Dz CjWkcUGcbRIo5UmH5rs8byL4YlrPTwMfcqs7b8sY3jFWCeKa0EMo/gQdOcPKX+CW8p4G 3NPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059721; x=1709664521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=lzKJyFyt/BSZA7veABBLR2J+HmjQHIkuyQn6FByiZx+9hn2eWPScjptxI06ZWBLJy7 WQvTysdOXMHKTSqDyAtRqSo9nC7lsjbcBtw4CRh8RuEht9snJamS1DXlJWgujdNHVsyN nZ60nlJInxV17t6fiJGX0Ca5RtM1Bo8fgayu/bAPMcOvau3rIXv3DtfOl9ynHcy/QJv6 pm6f42SqpOAGy7g9kB1iDIZDxtTPyiJjihQj3qmuajhWvwtzcJEBEXHGuS+J/ydSjic4 dfhdzhW23OLqvnQYBsaBQX0pDDlNK0o8a1mk3LKCHEi96oNKyKJokv9eK6zJ7J5Z6Nln nohg== X-Gm-Message-State: AOJu0YyU33+/LNfZXjrbcrVk+kTXQNQ1U8M1q7d+RJ3Os69OxwEczHCK 8fwvceb8ZrexgywKf1+wbWyh/QE5MfvcuJpeFKEFByYW4V9I4iACXA3ZWsjPaHthvsTvV3JQAdQ / X-Google-Smtp-Source: AGHT+IF30TBkxuhs2mX9HYQ8yuqG1edE8Jc0TsI+BIaFzV3uILEv74NbmnTG0GCbyyRnDLE49XWsNg== X-Received: by 2002:a05:6a00:ce:b0:6e5:2cc9:c898 with SMTP id e14-20020a056a0000ce00b006e52cc9c898mr7190892pfj.26.1709059720912; Tue, 27 Feb 2024 10:48:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 03/14] linux-user/elfload: Tidy fill_note_info and struct elf_note_info Date: Tue, 27 Feb 2024 08:48:22 -1000 Message-Id: <20240227184833.193836-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059897435100003 Content-Type: text/plain; charset="utf-8" In fill_note_info, there were unnecessary checks for success of g_new/g_malloc. But these structures do not need to be dyamically allocated at all, and can in fact be statically allocated within the parent structure. This removes all error paths from fill_note_info, so change the return type to void. Change type of signr to match both caller (elf_core_dump) and callee (fill_prstatus), which both use int for signr. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 48 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 7b3a2c20f2..cc43487a37 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4066,10 +4066,12 @@ struct elf_thread_status { int num_notes; }; =20 +#define NUMNOTES 3 + struct elf_note_info { - struct memelfnote *notes; - struct target_elf_prstatus *prstatus; /* NT_PRSTATUS */ - struct target_elf_prpsinfo *psinfo; /* NT_PRPSINFO */ + struct memelfnote notes[NUMNOTES]; + struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ + struct target_elf_prpsinfo psinfo; /* NT_PRPSINFO */ =20 QTAILQ_HEAD(, elf_thread_status) thread_list; #if 0 @@ -4117,7 +4119,7 @@ static void fill_auxv_note(struct memelfnote *, const= TaskState *); static void fill_elf_note_phdr(struct elf_phdr *, int, off_t); static size_t note_size(const struct memelfnote *); static void free_note_info(struct elf_note_info *); -static int fill_note_info(struct elf_note_info *, long, const CPUArchState= *); +static void fill_note_info(struct elf_note_info *, int, const CPUArchState= *); static void fill_thread_info(struct elf_note_info *, const CPUArchState *); =20 static int dump_write(int, const void *, size_t); @@ -4514,44 +4516,33 @@ static void fill_thread_info(struct elf_note_info *= info, const CPUArchState *env info->notes_size +=3D note_size(&ets->notes[0]); } =20 -static int fill_note_info(struct elf_note_info *info, - long signr, const CPUArchState *env) +static void fill_note_info(struct elf_note_info *info, + int signr, const CPUArchState *env) { -#define NUMNOTES 3 CPUState *cpu =3D env_cpu((CPUArchState *)env); TaskState *ts =3D (TaskState *)cpu->opaque; - int i; =20 memset(info, 0, sizeof (*info)); QTAILQ_INIT(&info->thread_list); =20 - info->notes =3D g_new0(struct memelfnote, NUMNOTES); - if (info->notes =3D=3D NULL) - return (-ENOMEM); - info->prstatus =3D g_malloc0(sizeof (*info->prstatus)); - if (info->prstatus =3D=3D NULL) - return (-ENOMEM); - info->psinfo =3D g_malloc0(sizeof (*info->psinfo)); - if (info->prstatus =3D=3D NULL) - return (-ENOMEM); - /* * First fill in status (and registers) of current thread * including process info & aux vector. */ - fill_prstatus(info->prstatus, ts, signr); - elf_core_copy_regs(&info->prstatus->pr_reg, env); + fill_prstatus(&info->prstatus, ts, signr); + elf_core_copy_regs(&info->prstatus.pr_reg, env); fill_note(&info->notes[0], "CORE", NT_PRSTATUS, - sizeof (*info->prstatus), info->prstatus); - fill_psinfo(info->psinfo, ts); + sizeof(info->prstatus), &info->prstatus); + fill_psinfo(&info->psinfo, ts); fill_note(&info->notes[1], "CORE", NT_PRPSINFO, - sizeof (*info->psinfo), info->psinfo); + sizeof(info->psinfo), &info->psinfo); fill_auxv_note(&info->notes[2], ts); info->numnote =3D 3; =20 info->notes_size =3D 0; - for (i =3D 0; i < info->numnote; i++) + for (int i =3D 0; i < info->numnote; i++) { info->notes_size +=3D note_size(&info->notes[i]); + } =20 /* read and fill status of all threads */ WITH_QEMU_LOCK_GUARD(&qemu_cpu_list_lock) { @@ -4562,8 +4553,6 @@ static int fill_note_info(struct elf_note_info *info, fill_thread_info(info, cpu_env(cpu)); } } - - return (0); } =20 static void free_note_info(struct elf_note_info *info) @@ -4575,10 +4564,6 @@ static void free_note_info(struct elf_note_info *inf= o) QTAILQ_REMOVE(&info->thread_list, ets, ets_link); g_free(ets); } - - g_free(info->prstatus); - g_free(info->psinfo); - g_free(info->notes); } =20 static int write_note_info(struct elf_note_info *info, int fd) @@ -4694,8 +4679,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) goto out; =20 /* fill in the in-memory version of notes */ - if (fill_note_info(&info, signr, env) < 0) - goto out; + fill_note_info(&info, signr, env); =20 offset +=3D sizeof (elf); /* elf header */ offset +=3D (segs + 1) * sizeof (struct elf_phdr); /* program heade= rs */ --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059882; cv=none; d=zohomail.com; s=zohoarc; b=UFJO1mTtcMOq/9VlkEracoLmckWQh76RQPuC4oSk47Vbd/DYqqhDX9zQ3uYAIml14ccjvu6aA8XK+0qu8hbVqLfHUVsJSaV2o988CbNRefoZ2gV78sZS2/TExZCU8ajfScULBc5SuQh08LUJonNCrt5qlzgd1ps2T/U/e06W4iI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059882; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=VixIS+vxpdf+NG6YZIdv3fC+lPiEZDo6zKK8dIj1z0wgqC7szi/496l5T6xwWcT2rtzFE4vSpvC2acF98FUQdFzqowyfDVfBmCGg17C3nl6aSWSpLYgAgEeAQRhXLpWVcC7QFB8u+rr57NHNBVUZZTCuPIdCMXw5dPY0EJwCsYo= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059882604644.6514378772932; Tue, 27 Feb 2024 10:51:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VT-0006WZ-8N; Tue, 27 Feb 2024 13:48:47 -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 1rf2VR-0006Vy-83 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:45 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VP-0001TM-LJ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:44 -0500 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6da202aa138so3146822b3a.2 for ; Tue, 27 Feb 2024 10:48:43 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059722; x=1709664522; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=OxK0o86DootcJA/PGAIEqljBMZ2pcp5uozj74eTAIIF7l8CDGiujiSMd7d0rKtfGGW 8hLBmHrFV8r+wqEcV8LamQm/8isQ3IjYM/lzhfYZ05oEoenj6IQvCufH+HcFRKgjYY0F K6l9rPw9kjj3nDVj9NcfHIYzRq6wLezNaXVO33NG5jxgA6A2NcirkOsYJEAsoy3BfQSv hF7OJ2/EGRx4mFEFS6HRUwl3sH5iPdu14oimDHcyIYC/UVXcpmokFTAHkScktD/hVDlF FXbhLdcLlNvzuuqjZfy8fstYm/KsyEGy81g22kZgoPD451NEi3N7LMA68tnZcpD4rfv+ 384A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059722; x=1709664522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=bLBybGEm0OF3BSCZUfz5/fBIPPktopZoh0hiyTqmId5lGtYeLKCc2lFR/uezBos2Q8 tT3n3rO5yBNwk7S/lsp6liB2l7gtbveRH8ouH1uFAofyYL7k6CNQ5B/A+mH/ltFWILCa fAaft0bbXi4aKPVcZ5QX6+LoW9clqJDCKggtIYoRmDiFLs/wTZae15LndobPd1yN3EcP /Qb+fZ+LAC9DdUfIP8FV+jQuRGAG4mVCS4quLt0ZbUJaHTSr2pbHkDlHDDXTJivyVtfC 857PXcCvrvMz+SlFJSXPGmzi/fYwCxP4k7x0TXDPjilWZH4tnoCabW15nAwt3aDOWyNN 1aKA== X-Gm-Message-State: AOJu0Yx5EPQBNz8oqiI+5qpZR3Dlmuh2uvHfyP+QAv3sLSrfRTA+RXy6 PtBk2YjVQzIoBr05GcFQkS9i2n3nRUMWpaGb0Ursn97Pj/4Uwc2MkfauTycAaJzkl4TgLopN0cK B X-Google-Smtp-Source: AGHT+IFg+iVNWZ+9fJ0/jQQHfCeuyonZ5yzNXN582wH8RQlWA1PEJhjT83ehpvoPFfrH/og9tZDzdw== X-Received: by 2002:a05:6a00:987:b0:6e5:8d9:d59a with SMTP id u7-20020a056a00098700b006e508d9d59amr11052223pfg.16.1709059722234; Tue, 27 Feb 2024 10:48:42 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 04/14] linux-user/elfload: Stack allocate struct mm_struct Date: Tue, 27 Feb 2024 08:48:23 -1000 Message-Id: <20240227184833.193836-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059883353100001 Content-Type: text/plain; charset="utf-8" Ignoring the fact that g_malloc cannot fail, the structure is quite small and might as well be allocated locally. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index cc43487a37..98b82b1a49 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4099,7 +4099,7 @@ struct mm_struct { int mm_count; /* number of mappings */ }; =20 -static struct mm_struct *vma_init(void); +static void vma_init(struct mm_struct *); static void vma_delete(struct mm_struct *); static int vma_add_mapping(struct mm_struct *, target_ulong, target_ulong, abi_ulong); @@ -4174,17 +4174,10 @@ static inline void bswap_note(struct elf_note *en) = { } * thread that received the signal is stopped. */ =20 -static struct mm_struct *vma_init(void) +static void vma_init(struct mm_struct *mm) { - struct mm_struct *mm; - - if ((mm =3D g_malloc(sizeof (*mm))) =3D=3D NULL) - return (NULL); - mm->mm_count =3D 0; QTAILQ_INIT(&mm->mm_mmap); - - return (mm); } =20 static void vma_delete(struct mm_struct *mm) @@ -4195,7 +4188,6 @@ static void vma_delete(struct mm_struct *mm) QTAILQ_REMOVE(&mm->mm_mmap, vma, vma_link); g_free(vma); } - g_free(mm); } =20 static int vma_add_mapping(struct mm_struct *mm, target_ulong start, @@ -4638,7 +4630,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) struct elfhdr elf; struct elf_phdr phdr; struct rlimit dumpsize; - struct mm_struct *mm =3D NULL; + struct mm_struct mm; off_t offset =3D 0, data_offset =3D 0; int segs =3D 0; int fd =3D -1; @@ -4664,11 +4656,10 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) * set up structure containing this information. After * this point vma_xxx functions can be used. */ - if ((mm =3D vma_init()) =3D=3D NULL) - goto out; + vma_init(&mm); =20 - walk_memory_regions(mm, vma_walker); - segs =3D vma_get_mapping_count(mm); + walk_memory_regions(&mm, vma_walker); + segs =3D vma_get_mapping_count(&mm); =20 /* * Construct valid coredump ELF header. We also @@ -4701,7 +4692,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) * Write program headers for memory regions mapped in * the target process. */ - for (vma =3D vma_first(mm); vma !=3D NULL; vma =3D vma_next(vma)) { + for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { (void) memset(&phdr, 0, sizeof (phdr)); =20 phdr.p_type =3D PT_LOAD; @@ -4738,7 +4729,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) /* * Finally we can dump process memory into corefile as well. */ - for (vma =3D vma_first(mm); vma !=3D NULL; vma =3D vma_next(vma)) { + for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { abi_ulong addr; abi_ulong end; =20 @@ -4767,8 +4758,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) =20 out: free_note_info(&info); - if (mm !=3D NULL) - vma_delete(mm); + vma_delete(&mm); (void) close(fd); =20 if (errno !=3D 0) --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059858; cv=none; d=zohomail.com; s=zohoarc; b=diI30w/DJpmL2uOu7482ynLFWauZVpYO7aPv4Fw6UI1cLklyzeY6BNbj76uQ65pVO33VpcO70GM2ma7XxxIfpFVehTvQNLhX3Utk189/xjxtPUKaq7NUPC5LoM5yvESFAsU7oUifKhnApCX2Knl288rk8R18Md5+qzqquPSu74A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059858; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=msfTd5b0wXNpkTjH4qQ0oMBWlE+XJA0PV+l0a8fYF1Zs7pBBtOlP8heyRu31FIRl5iYoa0OWf7LBXuIH2BP1D6PLODTE/MFL3GEJ4WWHI9MX9vdcgOlKpDielSy2nhNhc1XYN/Li9LvsUe68tRuzmVEVMcDIfTfJ/sQy+seidh8= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17090598584523.6894543434469824; Tue, 27 Feb 2024 10:50:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VT-0006X5-UJ; Tue, 27 Feb 2024 13:48:48 -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 1rf2VS-0006WP-BW for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:46 -0500 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VQ-0001TX-VG for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:46 -0500 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6e445b4f80bso2587881a34.0 for ; Tue, 27 Feb 2024 10:48:44 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059723; x=1709664523; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=SaZFfP9rtg11C3ruHczOU9+wbj+9BQi/geWUqoL1W6ZJZT3Eupta3nxSXayim1Krpb roRxh8n9iUjlGiOyebxG24VzxjYYOlYJDPcqI2es0tLJsXcvT8+VOLkCT36B1LNt8lIX rjVRl24JRgigYlB4OMCP4WWoUHE0nVkX59Bvb0C4wCclav+99mw6Ea+jCl8GQL+/KR3g BFJ8lNZ1TccAGeefkyRLbieLTmd5EHvcqCnRbeNCS7z9mb2K1TzLdHPi0dsKJP+OWKjz USGbef61hRO0JDczE43pUYcg0W2EBROWpCmsijtreHA+CLMiAuJgm/VVrLQ8FOqhUUAw O67g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059723; x=1709664523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=QNFg/Ky1TSVyzeNJ311HFDv1cfkz8+6GgL0T6VUTGetcA8AX58k1Yh0gzbzdwSIm4e vUZWSJKiWciP+xkr11Mv38Gi/tgu9AGOMhhSsAUuEUbuxuEG8xOB79I/nbs8cZrmGx2k j3pEC8Rsj5qvkKJaE8ukmk9vlXjA21+19MV7gbqSPYKIzMU8cs8NyolbPxqxKCcMgq1Y PW8p5HsS+qAObwephQ0Cuo27WUudr2wQRPE42vK6pRT6b3ChxpQg59QOaKHZLdQvTSkG f1ZjS8jF7RI79UnzHOP13e8P7Mkf+eNyICwLrXK5AxZWk3Bt2ghPqeyO596zN6eYBSiB C2MA== X-Gm-Message-State: AOJu0Yxi5KmwInBn8Iz06HjdZcPpOe58cJ/JU2EDcihNkB78AYTpyVyL U8sKQ7xiu21lz8yH/3tpbznHAEQ0RgxaFnXwPskIixbSVz20WaTmdF5Q5N8CA+P1Pl2n/4scl39 y X-Google-Smtp-Source: AGHT+IEyLVLD8uA5G6PJo6Aq97EcdNVif9Qz06281L7bF3lKNKunHKBbpGUimCpxu1FmLRAAzy88VA== X-Received: by 2002:a05:6870:700e:b0:21f:c705:7d8c with SMTP id u14-20020a056870700e00b0021fc7057d8cmr13325878oae.26.1709059723679; Tue, 27 Feb 2024 10:48:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 05/14] linux-user/elfload: Latch errno before cleanup in elf_core_dump Date: Tue, 27 Feb 2024 08:48:24 -1000 Message-Id: <20240227184833.193836-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::32c; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32c.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059859282100005 Content-Type: text/plain; charset="utf-8" On the off-chance that one of the cleanup functions changes errno, latch the errno that we want to return beforehand. Flush errno to 0 upon success, rather than at the beginning. No need to avoid negation of 0. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 98b82b1a49..39d9ef9acc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4634,8 +4634,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) off_t offset =3D 0, data_offset =3D 0; int segs =3D 0; int fd =3D -1; - - errno =3D 0; + int ret; =20 if (prctl(PR_GET_DUMPABLE) =3D=3D 0) { return 0; @@ -4755,15 +4754,14 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) goto out; } } + errno =3D 0; =20 out: + ret =3D -errno; free_note_info(&info); vma_delete(&mm); - (void) close(fd); - - if (errno !=3D 0) - return (-errno); - return (0); + close(fd); + return ret; } #endif /* USE_ELF_CORE_DUMP */ =20 --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059874; cv=none; d=zohomail.com; s=zohoarc; b=khHQEOAEPHLJC441PgymOqXYnN50RAjAWqE5fn3t+YXGTcnEyAAMkJXRX4FsE31OL7P94defBYIl0qi6+gvYwYLGPXCWvnfh2MdPSRDS7YR1H4VKrYOuPf9hdmdzowFNEzYhvLUYcQRdCCreBFefDXaIcg8vH8wTzRfk7nfhPPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059874; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=etIsBpDO6FZ9kOpE/f7Fy5s7PYFcGORIZzKH08D4puBXvoULO0Uh08cYRQCa7QkijG2vpisDgMqgehtYdUCPwwiy1yxq8o3X5jz4jR6us/z9AqA5m9gfSwSYOfx6HoQuRUEA8id4F1b7PtLSt2yidOdwq4tEfzIF5bazXZmWqFY= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059874025144.04543754551742; Tue, 27 Feb 2024 10:51:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VV-0006Xi-4I; Tue, 27 Feb 2024 13:48:49 -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 1rf2VT-0006Wb-Hs for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:47 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VS-0001Tp-4p for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:47 -0500 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c1a7d51fb5so1209222b6e.1 for ; Tue, 27 Feb 2024 10:48:45 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059725; x=1709664525; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=H8CbB2ObOaECqOHiTpuCP40k83kMXOXglRn98bVANnPu4CuOSbphs5JzntlE9p06XA DisI2QF3aWWfhMPD6GKsEiggz1z6iIZLWOBi+iNEU2Xnwdv9tkpEIGqpoTBg/0dxl5t4 B566IxnFyL5x3wJP4RcJYVLrfGxXPLr8y5fBRsOMYEEZv5PqRh0HdnyNNoJOnznZ1nxO jXjzfmrNSU7wlSlZYIHdti/0ylxRCaHTYnti0op0fDBnkoy/9ZXYZowEre/w3eE5YOwl QoawxWchR8tsrTQhzikZdOQXTbbVt0T/5nQ0TFkd0PXsxeUMPQR7BWCS9HV3ZKAtV8kI 0Lpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059725; x=1709664525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=JgLZunwSZi81ci/+f1ZQ5g0hnRRdzKvKChN1fOoDL/pS01Ip/ZDNPaB5ETM8VncEiT +3rMMlTJ9HwrL6j6661YeatsD8+b7wyAP4JCU9b3XWPUf+P+maubzKGpPKfJWoI1Xp5C Ik1AOrRuUlH6NW+QgHuGRJI2ob8Qa9lwmV6JMkDJe+GjRqzuM7yVYo8jmg3/O54fJ31/ Rz7hY6C/lzSdZ8sizf+kGu/SoRQknhBukHP43mVvtVuBPfSPpXVpza1WqqZeEhLUwLa/ Q2UKT/58NJS87LDzAl+1DKKmsutVQrPDh8JinUOJwnHn9a2aAWhrEHEs/kV+5ztXqIf3 wjzw== X-Gm-Message-State: AOJu0YyTkughH2cjgf8p8pG3N/taK18klJ93nU0TLYpactasJIGFrC+q XjUqtu8xBHnyFKOFcZTxDII63U49w8R+OZYpLDx1r51LGdSIQc5l07Lh6HynkhfEmjTYO80FDie a X-Google-Smtp-Source: AGHT+IHPgaf2Z/HkkAx0p+YsBbf1jizdskZ63ajWuPrVgrQPxF4PpwXiHII/nfbL95AM4M6LfyADzA== X-Received: by 2002:a05:6808:280e:b0:3bf:d775:616e with SMTP id et14-20020a056808280e00b003bfd775616emr2563878oib.53.1709059725010; Tue, 27 Feb 2024 10:48:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 06/14] linux-user/elfload: Open core file after vma_init Date: Tue, 27 Feb 2024 08:48:25 -1000 Message-Id: <20240227184833.193836-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::231; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x231.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059875302100002 Content-Type: text/plain; charset="utf-8" Swap the ordering of vma_init and open. This will be necessary for further changes, and adjusts the error cleanup path. Narrow the scope of corefile, as the variable can be freed immediately after use in open(). Signed-off-by: Richard Henderson --- linux-user/elfload.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 39d9ef9acc..877799e9c7 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4625,7 +4625,6 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) const CPUState *cpu =3D env_cpu((CPUArchState *)env); const TaskState *ts =3D (const TaskState *)cpu->opaque; struct vm_area_struct *vma =3D NULL; - g_autofree char *corefile =3D NULL; struct elf_note_info info; struct elfhdr elf; struct elf_phdr phdr; @@ -4644,12 +4643,6 @@ static int elf_core_dump(int signr, const CPUArchSta= te *env) return 0; } =20 - corefile =3D core_dump_filename(ts); - - if ((fd =3D open(corefile, O_WRONLY | O_CREAT, - S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) - return (-errno); - /* * Walk through target process memory mappings and * set up structure containing this information. After @@ -4657,6 +4650,15 @@ static int elf_core_dump(int signr, const CPUArchSta= te *env) */ vma_init(&mm); =20 + { + g_autofree char *corefile =3D core_dump_filename(ts); + fd =3D open(corefile, O_WRONLY | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + } + if (fd < 0) { + goto out; + } + walk_memory_regions(&mm, vma_walker); segs =3D vma_get_mapping_count(&mm); =20 --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059859; cv=none; d=zohomail.com; s=zohoarc; b=non7QP9sZdNj9ct7KiMOGyJ1jHG7aDl2ADieKoqjZbojWoJTwIK4SfsJtCKv1J6Q17khAOd195dNWG0F9BT/QfrNDJY6DntQTMy+qg+mWzmCfq58h12vG9AMPXC530QN6CAaDnhRl0YmHWZciMOO09CqaGI2ccSmTjOeXvWLq+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059859; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zYkpQqoaMHDWxrt9KPP15xrK5H9LSGOtZoW36Ee0L04=; b=jDZdmWa8X2QvTlAWgYKC/HK6COyzYF659sF6uaSMjoMaQvGgwDstmBuvkGDG5WVuLfK735AAmmbcK2VQg8vJYMlW+BN1ovszmakxPcoZG51ZM4RUm43S5l2BQyqQfjcVtc81dexwgGQXiB2eZqgjKE0voaqfwOo5U5bZgWgLST0= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059859199184.12665523820453; Tue, 27 Feb 2024 10:50:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VW-0006YM-NC; Tue, 27 Feb 2024 13:48:50 -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 1rf2VV-0006Xh-0F for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:49 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VT-0001U9-FV for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:48 -0500 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3c1af1e8b7eso445288b6e.2 for ; Tue, 27 Feb 2024 10:48:47 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059726; x=1709664526; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zYkpQqoaMHDWxrt9KPP15xrK5H9LSGOtZoW36Ee0L04=; b=VA8hDsFtP/U5ZrVOFtU3Ar9rJaOaPmhzPwUj6uOh0SB5bc7mAJN+uFnI0GiTccwyJ+ mTrwRMP81OXovg9aYIRzXYnbsCZwerjMnyaDXi8X6URpMvgEAYI7znB6oV8brnJWdoWK rWtM64LlFJAuM8Cugkhvg6j4XRXLXi3NnqSC8YOdzxP3hgkcCuPhuI3H79Jk5Nobmw0s m3osep7lFdJ0eNTsZ9YO/SDtgq/RqrsU/jvWZHeiyrZAl6Ca8vu4JzsOAnm01LiFdDp5 w7yRLACAqp5G7OedZWCpql1Br9VTY31BHWeofdTS6ZLRgP8x4kP/uSVwqr4zjw1SEse9 u+Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059726; x=1709664526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zYkpQqoaMHDWxrt9KPP15xrK5H9LSGOtZoW36Ee0L04=; b=Ri5/wioFFVC8qKQ6eF9v5lUZ6s2QR3c4GG0NBse32ufmFYCjOS8I5zTMn4DJorgEdJ EtbnMaLRF5WaC3NxV90wrVbfKX64M7Nu0vaS8wABZn2O/3NWNrHdq3mcyoIYKY37gpKD R6tDRtJuaHQEQ+jw9ZRBKXy0jQjMtUCNjg2EGjfepSiGRebY2ahfk+hWg15svcLzA7L5 iPD220KHKaGvXHfQn+R3w4dhEdzNeFhdL3cCkjXPLa28bH1WNs91Ygq6fxUxsKGIr2lS 3SuloKwbLz7V5NN5bMa9l4t+qLBYV5+E3YaaYktjsjI8JH+7PI8nsNITQeO0jfOZ5aYK 0RbA== X-Gm-Message-State: AOJu0YwQs/HIi+oV10yYXGt8qP+rmqOJDj83+83yjitsZIEkbnfv2qNz iTP7iIwPacC2d8TjOvTYCvR2hEnzpsqIunbPml5xiXyYfFfD+xt0hpfwM2S0+5cEgWavD8Zah0G U X-Google-Smtp-Source: AGHT+IGbroZPuT2hux0sBwLB5diBCFIKWAkiEFoVPCzX9kQ/QIs+F0lBbebIqJzQswjoifmIiV7/Dg== X-Received: by 2002:aca:130f:0:b0:3c1:6526:1342 with SMTP id e15-20020aca130f000000b003c165261342mr2910324oii.45.1709059726331; Tue, 27 Feb 2024 10:48:46 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 07/14] linux-user/elfload: Truncate core file on open Date: Tue, 27 Feb 2024 08:48:26 -1000 Message-Id: <20240227184833.193836-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::22f; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22f.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059861275100009 Content-Type: text/plain; charset="utf-8" While we usually create a new corefile, truncate otherwise. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 877799e9c7..16dd08a828 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4652,7 +4652,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) =20 { g_autofree char *corefile =3D core_dump_filename(ts); - fd =3D open(corefile, O_WRONLY | O_CREAT, + fd =3D open(corefile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } if (fd < 0) { --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059750; cv=none; d=zohomail.com; s=zohoarc; b=asSw9gFVvUy9AnifkS2SHDwK7Ndrzxm1VXsgU9yo1ldvsgPmhFN/R4VPqmLB/LqwPfsWw034qTiJ/DgXzS4CyR3lMNTjIgPwJJBVezoDMuE/JdaOYV7gAZCcJy4KReWwyRCkstoT1HfIhxKcd05hrQrwAbWzWNGrvNhg1Yq+mUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059750; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7NxH+YjseDTpq8veEE2IUMndw319v6C2n3pI3OsSxXo=; b=nfPhwcwc1E221dqJTfLraFDQHEL+eYtcpYSd63IQIm2ftmVZDigqak39c+AbFEmTAj3uInFth5/D/ey+PA4K8XPLJKV7g54uVcEgBZUd3avp6bDw+YtzdQ03ldulmkgpV+XjehLyJur8wkeuXk/ghhVWDuxCzWEX8PuZKK+WRj4= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059750657854.4022652641646; Tue, 27 Feb 2024 10:49:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VX-0006Ya-Ug; Tue, 27 Feb 2024 13:48:51 -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 1rf2VW-0006YC-Bu for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:50 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VU-0001US-RQ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:50 -0500 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6e508725b64so1174325b3a.3 for ; Tue, 27 Feb 2024 10:48:48 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059727; x=1709664527; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7NxH+YjseDTpq8veEE2IUMndw319v6C2n3pI3OsSxXo=; b=HzMcsNAAMqZdnfye7m1h4b6Gsv7P0ePdXCS2W4PLNFdWeuLUHGk99Zwsnb2X+ZUZgE XdpsjQY99PlF8YKwM2OXhNcIiahA1me9dnE7ZqyoHni/h3OzGOMkGwyZBSjIa7c9W1ts Zwx2WByyI5TU13vmKO+85UIXzffUAURXZayBg9po2TLa/VP3U2EUG+y2/lAnw6MJX0Av PhWcjHb+QrYe+OndqDkGJUKs9ueX67z1wy1/EsvhOSH4ILZg0zK92d2YLGdJPNkRIBXE AjSGGjbfODo2Z3XbaNJJlxqH5p22M53i9ODPI00PP0YXSJ7UVvjn5fGiFre+OOfbL0hP angQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059727; x=1709664527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7NxH+YjseDTpq8veEE2IUMndw319v6C2n3pI3OsSxXo=; b=lpag/myTUOFdyYDs1d0KWfi27MgwcE7QFuL9DupccU4oA/u2BJeMYVx0tA/QabbQhH 3fIccpcwbas9MgUOMOaLiPGW4tVYSm7F274qUNAAOqupnmrSyyBJ/AlZsXAe9GApS4eU HWqvFEwtMi6muUu4Wktdt2YaxOK4zkwz4J0GKCsPHi58JeYUkgPLz0+H6t6P/KBgSOqj IuWP2WbscCIXQpnrC7e9Fa6wTl3HLakOzBcTeS8Rz7oDu/Y/d3PZN5nVPerI14T0Gepp B/85lZU8xdO3rEeyZDU0b8PuOLukhv18x0q7XoD11Jphfobu2GE2xYoHr5qVmGphBqa3 QFrQ== X-Gm-Message-State: AOJu0YyPgB67ZMnlDqHyVO2cbsLKwnrkfo6LF6muwNXJlLUQV1W6y/bc SlqMSxTMV/UiKWivg8Eso/wuexM2qyEDPjRj4Luqe7be0KEgKlWV0xWfcGuT+aBbrfwxm/29hsz w X-Google-Smtp-Source: AGHT+IFKhgFPVqYOgKrGIROfzwRi4WbdBCaBhFn8IVpngE0/HMnomyFasswSbMm2J4vEgsBk8LQfzQ== X-Received: by 2002:a05:6a00:23d2:b0:6e4:f753:1e12 with SMTP id g18-20020a056a0023d200b006e4f7531e12mr10599709pfc.28.1709059727595; Tue, 27 Feb 2024 10:48:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 08/14] linux-user/elfload: Lock cpu list and mmap during elf_core_dump Date: Tue, 27 Feb 2024 08:48:27 -1000 Message-Id: <20240227184833.193836-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059751826100006 Content-Type: text/plain; charset="utf-8" Do not allow changes to the set of cpus and memory regions while we are dumping core. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e --- linux-user/elfload.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 16dd08a828..6f9da721d7 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4537,13 +4537,11 @@ static void fill_note_info(struct elf_note_info *in= fo, } =20 /* read and fill status of all threads */ - WITH_QEMU_LOCK_GUARD(&qemu_cpu_list_lock) { - CPU_FOREACH(cpu) { - if (cpu =3D=3D thread_cpu) { - continue; - } - fill_thread_info(info, cpu_env(cpu)); + CPU_FOREACH(cpu) { + if (cpu =3D=3D thread_cpu) { + continue; } + fill_thread_info(info, cpu_env(cpu)); } } =20 @@ -4643,6 +4641,9 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) return 0; } =20 + cpu_list_lock(); + mmap_lock(); + /* * Walk through target process memory mappings and * set up structure containing this information. After @@ -4760,6 +4761,8 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) =20 out: ret =3D -errno; + mmap_unlock(); + cpu_list_unlock(); free_note_info(&info); vma_delete(&mm); close(fd); --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059836; cv=none; d=zohomail.com; s=zohoarc; b=XqpVbhqdYBTjhDypdFAbl+F2gWrHmVu4vCauqZv0Y6aooMiyk/Ub0H6VyDEglyBI76d11eiZUyJkoNvY9usZxQ3UH6qloLqjJEzy53ifLd7V2op2wEiv1ATD3tr3586M1+zPfYJ1hMaTfRYdf/XlKH1NrwCMcu3An9FmuzB6Alw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059836; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wXgOJaiR1gNovC/J+sG7U6tnXruxoEFoxj+FOnROhG4=; b=Y8x2rILZkXrzZ1Lh10J/LeQoQm/dbMrDxw2mS76r+uZg6VRotillhP5XrZ+wfJqWYAZwq/kPcrIXJd3bgJWLTWVpWl6aTxBiHACShGmqaysdE7kU3uvJXvnZc0LIHdOEEzRvKHSaYZnSuHizKYdp/EdErn+TyYE0q3kbKva9AJg= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059836915428.5701394607157; Tue, 27 Feb 2024 10:50:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VZ-0006ZJ-IC; Tue, 27 Feb 2024 13:48:53 -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 1rf2VX-0006YY-Pb for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:51 -0500 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VW-0001Ur-1V for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:51 -0500 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3c1adc90830so592722b6e.0 for ; Tue, 27 Feb 2024 10:48:49 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059729; x=1709664529; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wXgOJaiR1gNovC/J+sG7U6tnXruxoEFoxj+FOnROhG4=; b=bxS0qcNFchlcccwfkEFRMTRnEclanIzJPb9ESOhjyUU9coWZ6Gvnfb2JSsmvmJ2bHR sJxX+IUpWqIsnjAGSBUQKTRAmmIR61/OYVa8GfIp8ZyzOudwEheKaqpjIzTALBKMZiMk qKfSTo8UwPBwcqbKEjbn3gOTMGdkvFaEIiwkp13ytZ94epk26DnpUwGw8PRYhBWFCg40 wtz/SZ1I40uIdw+AKgUBcg7sjCv/NtykxEdvSL3dDo3c+7iHzwTIt/6+tW0IFBihqJvS qqQxs9BHcWjVbLgyYzPEVEohJ11b+jPX2rGyzeC0mGhIfooVRwXl4LDNfqX7zLx8wfFq IzoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059729; x=1709664529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wXgOJaiR1gNovC/J+sG7U6tnXruxoEFoxj+FOnROhG4=; b=RdfcWO6gVWrqpBCJrCz3nAGUx430Dp5fW/tkxjb3G6PgxiZF57/DU14X7brxRwNwtV STJzuuU3XNAy6w30tdH+/QnMwDmCxPHlfkd9KjJK91dRPymL9IhXXB4mI1rL5WHUNzM0 3nKCfxjnPqWMUe4iblIggv7neqpVu4IaFagnD9W0bVmWStiJzyAd3YnBSVdPVgoqtx1y +Xq1LR3O29jQq1Zt2iwrMzOQwqkKj20yasV+RA/FfwsBliD2X9vprfWBS8mgk95Qyd4X dXGupmkMJodLGx3o0yFxEl7klwHRN1b0yJgyYqywD2s+fxX9U1O51RcUmGo7GW35tI9H F3SQ== X-Gm-Message-State: AOJu0YynwxN7/7+zdQcclZ49cSmPuswl3RK7CMW64FzTSuU2U5OOvwR0 TmHsja57I1VV1lN3QbO8v44P31PfcUpxXb0609Bz92uJOiBdrEAPlfZ6/+L4zwfC0HACEGhMhp+ / X-Google-Smtp-Source: AGHT+IFecdjYGJrB3tBf8/IytUYkfXQKKou0PIF9XO6tywkjgBi7OB5iRyDD82YZ9ZJQnCB0TOcbow== X-Received: by 2002:a05:6808:ec8:b0:3c1:83f8:35d6 with SMTP id q8-20020a0568080ec800b003c183f835d6mr3278919oiv.53.1709059728894; Tue, 27 Feb 2024 10:48:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 09/14] linux-user/elfload: Size corefile before opening Date: Tue, 27 Feb 2024 08:48:28 -1000 Message-Id: <20240227184833.193836-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::22a; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22a.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059837311100003 Content-Type: text/plain; charset="utf-8" Verify the size of the corefile vs the rlimit before opening and creating the core file at all. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 83 +++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 6f9da721d7..bad01bd2ef 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4270,6 +4270,16 @@ static int vma_walker(void *priv, target_ulong start= , target_ulong end, return (0); } =20 +static size_t size_note(const char *name, size_t datasz) +{ + size_t namesz =3D strlen(name) + 1; + + namesz =3D ROUND_UP(namesz, 4); + datasz =3D ROUND_UP(datasz, 4); + + return sizeof(struct elf_note) + namesz + datasz; +} + static void fill_note(struct memelfnote *note, const char *name, int type, unsigned int sz, void *data) { @@ -4428,27 +4438,9 @@ static int dump_write(int fd, const void *ptr, size_= t size) { const char *bufp =3D (const char *)ptr; ssize_t bytes_written, bytes_left; - struct rlimit dumpsize; - off_t pos; =20 bytes_written =3D 0; - getrlimit(RLIMIT_CORE, &dumpsize); - if ((pos =3D lseek(fd, 0, SEEK_CUR))=3D=3D-1) { - if (errno =3D=3D ESPIPE) { /* not a seekable stream */ - bytes_left =3D size; - } else { - return pos; - } - } else { - if (dumpsize.rlim_cur <=3D pos) { - return -1; - } else if (dumpsize.rlim_cur =3D=3D RLIM_INFINITY) { - bytes_left =3D size; - } else { - size_t limit_left=3Ddumpsize.rlim_cur - pos; - bytes_left =3D limit_left >=3D size ? size : limit_left ; - } - } + bytes_left =3D size; =20 /* * In normal conditions, single write(2) should do but @@ -4622,16 +4614,15 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) { const CPUState *cpu =3D env_cpu((CPUArchState *)env); const TaskState *ts =3D (const TaskState *)cpu->opaque; - struct vm_area_struct *vma =3D NULL; + struct vm_area_struct *vma; struct elf_note_info info; struct elfhdr elf; struct elf_phdr phdr; struct rlimit dumpsize; struct mm_struct mm; - off_t offset =3D 0, data_offset =3D 0; - int segs =3D 0; + off_t offset, note_offset, data_offset; + int segs, cpus, ret; int fd =3D -1; - int ret; =20 if (prctl(PR_GET_DUMPABLE) =3D=3D 0) { return 0; @@ -4646,10 +4637,36 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) =20 /* * Walk through target process memory mappings and - * set up structure containing this information. After - * this point vma_xxx functions can be used. + * set up structure containing this information. */ vma_init(&mm); + walk_memory_regions(&mm, vma_walker); + segs =3D vma_get_mapping_count(&mm); + + cpus =3D 0; + CPU_FOREACH(cpu) { + cpus++; + } + + offset =3D sizeof(struct elfhdr); + offset +=3D (segs + 1) * sizeof(struct elf_phdr); + note_offset =3D offset; + + offset +=3D size_note("CORE", ts->info->auxv_len); + offset +=3D size_note("CORE", sizeof(struct target_elf_prpsinfo)); + offset +=3D size_note("CORE", sizeof(struct target_elf_prstatus)) * cp= us; + offset =3D ROUND_UP(offset, ELF_EXEC_PAGESIZE); + data_offset =3D offset; + + for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { + offset +=3D vma_dump_size(vma); + } + + /* Do not dump if the corefile size exceeds the limit. */ + if (dumpsize.rlim_cur !=3D RLIM_INFINITY && dumpsize.rlim_cur < offset= ) { + errno =3D 0; + goto out; + } =20 { g_autofree char *corefile =3D core_dump_filename(ts); @@ -4660,9 +4677,6 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) goto out; } =20 - walk_memory_regions(&mm, vma_walker); - segs =3D vma_get_mapping_count(&mm); - /* * Construct valid coredump ELF header. We also * add one more segment for notes. @@ -4674,26 +4688,17 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) /* fill in the in-memory version of notes */ fill_note_info(&info, signr, env); =20 - offset +=3D sizeof (elf); /* elf header */ - offset +=3D (segs + 1) * sizeof (struct elf_phdr); /* program heade= rs */ - /* write out notes program header */ - fill_elf_note_phdr(&phdr, info.notes_size, offset); + fill_elf_note_phdr(&phdr, info.notes_size, note_offset); =20 - offset +=3D info.notes_size; if (dump_write(fd, &phdr, sizeof (phdr)) !=3D 0) goto out; =20 - /* - * ELF specification wants data to start at page boundary so - * we align it here. - */ - data_offset =3D offset =3D roundup(offset, ELF_EXEC_PAGESIZE); - /* * Write program headers for memory regions mapped in * the target process. */ + offset =3D data_offset; for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { (void) memset(&phdr, 0, sizeof (phdr)); =20 --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709060125; cv=none; d=zohomail.com; s=zohoarc; b=eBMxWcPlLjyS96DK5Id28WEpLMkioZXa8FyCeEWg5NAU1xLwDbJUSGiDLOPj9GysaGRHTXijJp/fO03lYXqErpUHhMwaKQRHRXYwOX4//a7Rh/NbY/azaC6E97+G+k5O7U9r2vUB38Kf33ZZKnQ20rPvVlHe431g62cZa8q2h+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709060125; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WPZgpp/cCi7t1E47Pxo1jS8aeNgwNI8GgVuo9d5SLyc=; b=nZE5GshgIMknA48SZ+foigTEM+a7I3eev/R49xlXlLEdFOxQuT+vRe1/XyM4ujlYDMBr1E0Cda10+I2hLnjYStF8P55+MQt1M5yHm53MqmxamtZGIWVY2YlIlcIF4lC/fgE4nRS3axAta98oT/wEsC3aUuBwBhtCS7l8AgsSgw0= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709060125033140.17155792208086; Tue, 27 Feb 2024 10:55:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2Vc-0006Zl-2J; Tue, 27 Feb 2024 13:48:56 -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 1rf2Va-0006ZP-1W for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:54 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VX-0001VN-GQ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:53 -0500 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c19bc08f96so2645611b6e.2 for ; Tue, 27 Feb 2024 10:48:51 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059730; x=1709664530; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WPZgpp/cCi7t1E47Pxo1jS8aeNgwNI8GgVuo9d5SLyc=; b=D1czXhJ6QU+VZohBRAcyBBcPjE1DJEf8IiKz+Ng2jlX2W2ixIU3JhM2sIlUk5i4qLQ QmrDib3d5eE2lf/jRJoE6y/uKvtode5pZRsBbJgm6bXqCu3L6gRvNcOaK8wDf7i/yB2/ zfevhoFt6iQgj43+QFRrWUaZLeI/JIla8y59w2FImSyIysMWanM3Sk3O+SpJn8ujOyK9 fL8YleYkFhPOXqrvhiOXe8SUq2PSXePAPjlbVWNGHUw2CFPK7c1O0cVBTjpW5zIhLei5 mWZNFP1ItJrmZuUw89zEtp9hyZaoIw/Kv0n1UT/hdrd7qKU8T1Fpgc9BTSqLFerLRpcn dMYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059730; x=1709664530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WPZgpp/cCi7t1E47Pxo1jS8aeNgwNI8GgVuo9d5SLyc=; b=NEhNg4yZU6S+d84zjNJdcxXToP4Jd/thF0cfLAo/7+IgYGiMJJc+xGNTs3fHnm4Lun DhX+ewprJTPESHtKOC03yC013Z+ZY/zLg3rpjQNCWNl13BaZ36/TmLiiW0Z6txG1Xini xCjiMVNusURhMy4i54uCfAWRcy6avlhYRNnJzCLOoukfVQTeA0OjgGIJoCPPQ6jrwmcL 1KhbN1ADSMOHoxzdeHwl+cXpBdpPxe8Xzs0+xt8zCgWeaseSBYazOuoDlJRRKnWl8SRE mgM1D2OYVXWD9Fjz2NIBQJ5lZcFyMU7C/LfF05jdXA5b3gOykoIhDY1zvJ+6V8bW/2TI BECg== X-Gm-Message-State: AOJu0YwV+YCdTexgsc9Q7EzfEfK2PsCTjWNS5Znde4N+jse1XyuTTUvm jOqSrYM6oZmbfXtbthqjGl88dkhWU2J9HAYT0KjQnL2ODqpsRM8tA5V9qHHSHCcENOG4v+KaSEr w X-Google-Smtp-Source: AGHT+IFZJ5s1qna3W00Ikj4U3dZqN1eIIEqd1xMGOKz3hqlWzcwfzAWLqMhdV9dBKEhgfM64aGxIdw== X-Received: by 2002:a05:6808:1143:b0:3c1:9a60:9248 with SMTP id u3-20020a056808114300b003c19a609248mr3180500oiu.14.1709059730367; Tue, 27 Feb 2024 10:48:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 10/14] linux-user/elfload: Write corefile elf header in one block Date: Tue, 27 Feb 2024 08:48:29 -1000 Message-Id: <20240227184833.193836-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::231; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x231.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709060126342100001 Content-Type: text/plain; charset="utf-8" Fixes a bug in which write_note() wrote namesz_rounded and datasz_rounded bytes, even though name and data pointers contain only the unrounded number of bytes. Instead of many small writes, allocate a block to contain all of the elf headers and all of the notes. Copy the data into the block piecemeal and the write it to the file as a chunk. This also avoids the need to lseek forward for alignment. --- linux-user/elfload.c | 410 ++++++++++++------------------------------- 1 file changed, 113 insertions(+), 297 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index bad01bd2ef..b8d07d8054 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4002,18 +4002,6 @@ int load_elf_binary(struct linux_binprm *bprm, struc= t image_info *info) * Example for ARM target is provided in this file. */ =20 -/* An ELF note in memory */ -struct memelfnote { - const char *name; - size_t namesz; - size_t namesz_rounded; - int type; - size_t datasz; - size_t datasz_rounded; - void *data; - size_t notesz; -}; - struct target_elf_siginfo { abi_int si_signo; /* signal number */ abi_int si_code; /* extra code */ @@ -4053,40 +4041,6 @@ struct target_elf_prpsinfo { char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ }; =20 -/* Here is the structure in which status of each thread is captured. */ -struct elf_thread_status { - QTAILQ_ENTRY(elf_thread_status) ets_link; - struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ -#if 0 - elf_fpregset_t fpu; /* NT_PRFPREG */ - struct task_struct *thread; - elf_fpxregset_t xfpu; /* ELF_CORE_XFPREG_TYPE */ -#endif - struct memelfnote notes[1]; - int num_notes; -}; - -#define NUMNOTES 3 - -struct elf_note_info { - struct memelfnote notes[NUMNOTES]; - struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ - struct target_elf_prpsinfo psinfo; /* NT_PRPSINFO */ - - QTAILQ_HEAD(, elf_thread_status) thread_list; -#if 0 - /* - * Current version of ELF coredump doesn't support - * dumping fp regs etc. - */ - elf_fpregset_t *fpu; - elf_fpxregset_t *xfpu; - int thread_status_size; -#endif - int notes_size; - int numnote; -}; - struct vm_area_struct { target_ulong vma_start; /* start vaddr of memory region */ target_ulong vma_end; /* end vaddr of memory region */ @@ -4110,22 +4064,6 @@ static abi_ulong vma_dump_size(const struct vm_area_= struct *); static int vma_walker(void *priv, target_ulong start, target_ulong end, unsigned long flags); =20 -static void fill_elf_header(struct elfhdr *, int, uint16_t, uint32_t); -static void fill_note(struct memelfnote *, const char *, int, - unsigned int, void *); -static void fill_prstatus(struct target_elf_prstatus *, const TaskState *,= int); -static int fill_psinfo(struct target_elf_prpsinfo *, const TaskState *); -static void fill_auxv_note(struct memelfnote *, const TaskState *); -static void fill_elf_note_phdr(struct elf_phdr *, int, off_t); -static size_t note_size(const struct memelfnote *); -static void free_note_info(struct elf_note_info *); -static void fill_note_info(struct elf_note_info *, int, const CPUArchState= *); -static void fill_thread_info(struct elf_note_info *, const CPUArchState *); - -static int dump_write(int, const void *, size_t); -static int write_note(struct memelfnote *, int); -static int write_note_info(struct elf_note_info *, int); - #ifdef BSWAP_NEEDED static void bswap_prstatus(struct target_elf_prstatus *prstatus) { @@ -4280,35 +4218,32 @@ static size_t size_note(const char *name, size_t da= tasz) return sizeof(struct elf_note) + namesz + datasz; } =20 -static void fill_note(struct memelfnote *note, const char *name, int type, - unsigned int sz, void *data) +static void *fill_note(void **pptr, int type, const char *name, size_t dat= asz) { - unsigned int namesz; + void *ptr =3D *pptr; + struct elf_note *n =3D ptr; + size_t namesz =3D strlen(name) + 1; =20 - namesz =3D strlen(name) + 1; - note->name =3D name; - note->namesz =3D namesz; - note->namesz_rounded =3D roundup(namesz, sizeof (int32_t)); - note->type =3D type; - note->datasz =3D sz; - note->datasz_rounded =3D roundup(sz, sizeof (int32_t)); + n->n_namesz =3D namesz; + n->n_descsz =3D datasz; + n->n_type =3D type; + bswap_note(n); =20 - note->data =3D data; + ptr +=3D sizeof(*n); + memcpy(ptr, name, namesz); =20 - /* - * We calculate rounded up note size here as specified by - * ELF document. - */ - note->notesz =3D sizeof (struct elf_note) + - note->namesz_rounded + note->datasz_rounded; + namesz =3D ROUND_UP(namesz, 4); + datasz =3D ROUND_UP(datasz, 4); + + *pptr =3D ptr + namesz + datasz; + return ptr + namesz; } =20 static void fill_elf_header(struct elfhdr *elf, int segs, uint16_t machine, uint32_t flags) { - (void) memset(elf, 0, sizeof(*elf)); + memcpy(elf->e_ident, ELFMAG, SELFMAG); =20 - (void) memcpy(elf->e_ident, ELFMAG, SELFMAG); elf->e_ident[EI_CLASS] =3D ELF_CLASS; elf->e_ident[EI_DATA] =3D ELF_DATA; elf->e_ident[EI_VERSION] =3D EV_CURRENT; @@ -4326,95 +4261,79 @@ static void fill_elf_header(struct elfhdr *elf, int= segs, uint16_t machine, bswap_ehdr(elf); } =20 -static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, off_t offset) +static void fill_elf_note_phdr(struct elf_phdr *phdr, size_t sz, off_t off= set) { phdr->p_type =3D PT_NOTE; phdr->p_offset =3D offset; - phdr->p_vaddr =3D 0; - phdr->p_paddr =3D 0; phdr->p_filesz =3D sz; - phdr->p_memsz =3D 0; - phdr->p_flags =3D 0; - phdr->p_align =3D 0; =20 bswap_phdr(phdr, 1); } =20 -static size_t note_size(const struct memelfnote *note) +static void fill_prstatus_note(void *data, const TaskState *ts, + CPUState *cpu, int signr) { - return (note->notesz); + /* + * Because note memory is only aligned to 4, and target_elf_prstatus + * may well have higher alignment requirements, fill locally and + * memcpy to the destination afterward. + */ + struct target_elf_prstatus prstatus =3D { + .pr_info.si_signo =3D signr, + .pr_cursig =3D signr, + .pr_pid =3D ts->ts_tid, + .pr_ppid =3D getppid(), + .pr_pgrp =3D getpgrp(), + .pr_sid =3D getsid(0), + }; + + elf_core_copy_regs(&prstatus.pr_reg, cpu_env(cpu)); + bswap_prstatus(&prstatus); + memcpy(data, &prstatus, sizeof(prstatus)); } =20 -static void fill_prstatus(struct target_elf_prstatus *prstatus, - const TaskState *ts, int signr) -{ - (void) memset(prstatus, 0, sizeof (*prstatus)); - prstatus->pr_info.si_signo =3D prstatus->pr_cursig =3D signr; - prstatus->pr_pid =3D ts->ts_tid; - prstatus->pr_ppid =3D getppid(); - prstatus->pr_pgrp =3D getpgrp(); - prstatus->pr_sid =3D getsid(0); - - bswap_prstatus(prstatus); -} - -static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState= *ts) +static void fill_prpsinfo_note(void *data, const TaskState *ts) { + /* + * Because note memory is only aligned to 4, and target_elf_prpsinfo + * may well have higher alignment requirements, fill locally and + * memcpy to the destination afterward. + */ + struct target_elf_prpsinfo psinfo; char *base_filename; - unsigned int i, len; - - (void) memset(psinfo, 0, sizeof (*psinfo)); + size_t len; =20 len =3D ts->info->env_strings - ts->info->arg_strings; - if (len >=3D ELF_PRARGSZ) - len =3D ELF_PRARGSZ - 1; - if (copy_from_user(&psinfo->pr_psargs, ts->info->arg_strings, len)) { - return -EFAULT; + len =3D MIN(len, ELF_PRARGSZ); + memcpy(&psinfo.pr_psargs, g2h_untagged(ts->info->arg_strings), len); + for (size_t i =3D 0; i < len; i++) { + if (psinfo.pr_psargs[i] =3D=3D 0) { + psinfo.pr_psargs[i] =3D ' '; + } } - for (i =3D 0; i < len; i++) - if (psinfo->pr_psargs[i] =3D=3D 0) - psinfo->pr_psargs[i] =3D ' '; - psinfo->pr_psargs[len] =3D 0; =20 - psinfo->pr_pid =3D getpid(); - psinfo->pr_ppid =3D getppid(); - psinfo->pr_pgrp =3D getpgrp(); - psinfo->pr_sid =3D getsid(0); - psinfo->pr_uid =3D getuid(); - psinfo->pr_gid =3D getgid(); + psinfo.pr_pid =3D getpid(); + psinfo.pr_ppid =3D getppid(); + psinfo.pr_pgrp =3D getpgrp(); + psinfo.pr_sid =3D getsid(0); + psinfo.pr_uid =3D getuid(); + psinfo.pr_gid =3D getgid(); =20 base_filename =3D g_path_get_basename(ts->bprm->filename); /* * Using strncpy here is fine: at max-length, * this field is not NUL-terminated. */ - (void) strncpy(psinfo->pr_fname, base_filename, - sizeof(psinfo->pr_fname)); - + strncpy(psinfo.pr_fname, base_filename, sizeof(psinfo.pr_fname)); g_free(base_filename); - bswap_psinfo(psinfo); - return (0); + + bswap_psinfo(&psinfo); + memcpy(data, &psinfo, sizeof(psinfo)); } =20 -static void fill_auxv_note(struct memelfnote *note, const TaskState *ts) +static void fill_auxv_note(void *data, const TaskState *ts) { - elf_addr_t auxv =3D (elf_addr_t)ts->info->saved_auxv; - elf_addr_t orig_auxv =3D auxv; - void *ptr; - int len =3D ts->info->auxv_len; - - /* - * Auxiliary vector is stored in target process stack. It contains - * {type, value} pairs that we need to dump into note. This is not - * strictly necessary but we do it here for sake of completeness. - */ - - /* read in whole auxv vector and copy it to memelfnote */ - ptr =3D lock_user(VERIFY_READ, orig_auxv, len, 0); - if (ptr !=3D NULL) { - fill_note(note, "CORE", NT_AUXV, len, ptr); - unlock_user(ptr, auxv, len); - } + memcpy(data, g2h_untagged(ts->info->saved_auxv), ts->info->auxv_len); } =20 /* @@ -4462,111 +4381,6 @@ static int dump_write(int fd, const void *ptr, size= _t size) return (0); } =20 -static int write_note(struct memelfnote *men, int fd) -{ - struct elf_note en; - - en.n_namesz =3D men->namesz; - en.n_type =3D men->type; - en.n_descsz =3D men->datasz; - - bswap_note(&en); - - if (dump_write(fd, &en, sizeof(en)) !=3D 0) - return (-1); - if (dump_write(fd, men->name, men->namesz_rounded) !=3D 0) - return (-1); - if (dump_write(fd, men->data, men->datasz_rounded) !=3D 0) - return (-1); - - return (0); -} - -static void fill_thread_info(struct elf_note_info *info, const CPUArchStat= e *env) -{ - CPUState *cpu =3D env_cpu((CPUArchState *)env); - TaskState *ts =3D (TaskState *)cpu->opaque; - struct elf_thread_status *ets; - - ets =3D g_malloc0(sizeof (*ets)); - ets->num_notes =3D 1; /* only prstatus is dumped */ - fill_prstatus(&ets->prstatus, ts, 0); - elf_core_copy_regs(&ets->prstatus.pr_reg, env); - fill_note(&ets->notes[0], "CORE", NT_PRSTATUS, sizeof (ets->prstatus), - &ets->prstatus); - - QTAILQ_INSERT_TAIL(&info->thread_list, ets, ets_link); - - info->notes_size +=3D note_size(&ets->notes[0]); -} - -static void fill_note_info(struct elf_note_info *info, - int signr, const CPUArchState *env) -{ - CPUState *cpu =3D env_cpu((CPUArchState *)env); - TaskState *ts =3D (TaskState *)cpu->opaque; - - memset(info, 0, sizeof (*info)); - QTAILQ_INIT(&info->thread_list); - - /* - * First fill in status (and registers) of current thread - * including process info & aux vector. - */ - fill_prstatus(&info->prstatus, ts, signr); - elf_core_copy_regs(&info->prstatus.pr_reg, env); - fill_note(&info->notes[0], "CORE", NT_PRSTATUS, - sizeof(info->prstatus), &info->prstatus); - fill_psinfo(&info->psinfo, ts); - fill_note(&info->notes[1], "CORE", NT_PRPSINFO, - sizeof(info->psinfo), &info->psinfo); - fill_auxv_note(&info->notes[2], ts); - info->numnote =3D 3; - - info->notes_size =3D 0; - for (int i =3D 0; i < info->numnote; i++) { - info->notes_size +=3D note_size(&info->notes[i]); - } - - /* read and fill status of all threads */ - CPU_FOREACH(cpu) { - if (cpu =3D=3D thread_cpu) { - continue; - } - fill_thread_info(info, cpu_env(cpu)); - } -} - -static void free_note_info(struct elf_note_info *info) -{ - struct elf_thread_status *ets; - - while (!QTAILQ_EMPTY(&info->thread_list)) { - ets =3D QTAILQ_FIRST(&info->thread_list); - QTAILQ_REMOVE(&info->thread_list, ets, ets_link); - g_free(ets); - } -} - -static int write_note_info(struct elf_note_info *info, int fd) -{ - struct elf_thread_status *ets; - int i, error =3D 0; - - /* write prstatus, psinfo and auxv for current thread */ - for (i =3D 0; i < info->numnote; i++) - if ((error =3D write_note(&info->notes[i], fd)) !=3D 0) - return (error); - - /* write prstatus for each thread */ - QTAILQ_FOREACH(ets, &info->thread_list, ets_link) { - if ((error =3D write_note(&ets->notes[0], fd)) !=3D 0) - return (error); - } - - return (0); -} - /* * Write out ELF coredump. * @@ -4615,14 +4429,13 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) const CPUState *cpu =3D env_cpu((CPUArchState *)env); const TaskState *ts =3D (const TaskState *)cpu->opaque; struct vm_area_struct *vma; - struct elf_note_info info; - struct elfhdr elf; - struct elf_phdr phdr; struct rlimit dumpsize; struct mm_struct mm; off_t offset, note_offset, data_offset; + size_t note_size; int segs, cpus, ret; int fd =3D -1; + CPUState *cpu_iter; =20 if (prctl(PR_GET_DUMPABLE) =3D=3D 0) { return 0; @@ -4644,7 +4457,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) segs =3D vma_get_mapping_count(&mm); =20 cpus =3D 0; - CPU_FOREACH(cpu) { + CPU_FOREACH(cpu_iter) { cpus++; } =20 @@ -4655,6 +4468,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) offset +=3D size_note("CORE", ts->info->auxv_len); offset +=3D size_note("CORE", sizeof(struct target_elf_prpsinfo)); offset +=3D size_note("CORE", sizeof(struct target_elf_prstatus)) * cp= us; + note_size =3D offset - note_offset; offset =3D ROUND_UP(offset, ELF_EXEC_PAGESIZE); data_offset =3D offset; =20 @@ -4678,61 +4492,64 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) } =20 /* - * Construct valid coredump ELF header. We also - * add one more segment for notes. + * There is a fair amount of alignment padding within the notes + * as well as preceeding the process memory. Allocate a zeroed + * block to hold it all. Write all of the headers directly into + * this buffer and then write it out as a block. */ - fill_elf_header(&elf, segs + 1, ELF_MACHINE, 0); - if (dump_write(fd, &elf, sizeof (elf)) !=3D 0) - goto out; + { + g_autofree void *header =3D g_malloc0(data_offset); + void *hptr, *dptr; =20 - /* fill in the in-memory version of notes */ - fill_note_info(&info, signr, env); + /* Create elf file header. */ + hptr =3D header; + fill_elf_header(hptr, segs + 1, ELF_MACHINE, 0); + hptr +=3D sizeof(struct elfhdr); =20 - /* write out notes program header */ - fill_elf_note_phdr(&phdr, info.notes_size, note_offset); + /* Create elf program headers. */ + fill_elf_note_phdr(hptr, note_size, note_offset); + hptr +=3D sizeof(struct elf_phdr); =20 - if (dump_write(fd, &phdr, sizeof (phdr)) !=3D 0) - goto out; + offset =3D data_offset; + for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma))= { + struct elf_phdr *phdr =3D hptr; =20 - /* - * Write program headers for memory regions mapped in - * the target process. - */ - offset =3D data_offset; - for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { - (void) memset(&phdr, 0, sizeof (phdr)); + phdr->p_type =3D PT_LOAD; + phdr->p_offset =3D offset; + phdr->p_vaddr =3D vma->vma_start; + phdr->p_paddr =3D 0; + phdr->p_filesz =3D vma_dump_size(vma); + offset +=3D phdr->p_filesz; + phdr->p_memsz =3D vma->vma_end - vma->vma_start; + phdr->p_flags =3D (vma->vma_flags & PROT_READ ? PF_R : 0) + | (vma->vma_flags & PROT_WRITE ? PF_W : 0) + | (vma->vma_flags & PROT_EXEC ? PF_X : 0); + phdr->p_align =3D ELF_EXEC_PAGESIZE; =20 - phdr.p_type =3D PT_LOAD; - phdr.p_offset =3D offset; - phdr.p_vaddr =3D vma->vma_start; - phdr.p_paddr =3D 0; - phdr.p_filesz =3D vma_dump_size(vma); - offset +=3D phdr.p_filesz; - phdr.p_memsz =3D vma->vma_end - vma->vma_start; - phdr.p_flags =3D vma->vma_flags & PROT_READ ? PF_R : 0; - if (vma->vma_flags & PROT_WRITE) - phdr.p_flags |=3D PF_W; - if (vma->vma_flags & PROT_EXEC) - phdr.p_flags |=3D PF_X; - phdr.p_align =3D ELF_EXEC_PAGESIZE; + bswap_phdr(phdr, 1); + hptr +=3D sizeof(struct elf_phdr); + } =20 - bswap_phdr(&phdr, 1); - if (dump_write(fd, &phdr, sizeof(phdr)) !=3D 0) { + /* Create the notes. */ + dptr =3D fill_note(&hptr, NT_AUXV, "CORE", ts->info->auxv_len); + fill_auxv_note(dptr, ts); + + dptr =3D fill_note(&hptr, NT_PRPSINFO, "CORE", + sizeof(struct target_elf_prpsinfo)); + fill_prpsinfo_note(dptr, ts); + + CPU_FOREACH(cpu_iter) { + dptr =3D fill_note(&hptr, NT_PRSTATUS, "CORE", + sizeof(struct target_elf_prstatus)); + fill_prstatus_note(dptr, ts, cpu_iter, + cpu_iter =3D=3D cpu ? signr : 0); + } + + if (dump_write(fd, header, data_offset) < 0) { goto out; } } =20 - /* - * Next we write notes just after program headers. No - * alignment needed here. - */ - if (write_note_info(&info, fd) < 0) - goto out; - - /* align data to page boundary */ - if (lseek(fd, data_offset, SEEK_SET) !=3D data_offset) - goto out; - /* * Finally we can dump process memory into corefile as well. */ @@ -4768,7 +4585,6 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) ret =3D -errno; mmap_unlock(); cpu_list_unlock(); - free_note_info(&info); vma_delete(&mm); close(fd); return ret; --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059819; cv=none; d=zohomail.com; s=zohoarc; b=l1c04TGCNBBUHU4LJmThLN8KSHvrFDZMMSV9KQbBEsF6IIbZHwpouQ3A+h6c4jON/x6JHuYd4RWFX7mIF9JCM0NTSQZRZlsScTIoihzMrNMxeCaOCyxLQClc282Up0ITSFOUEObXz14etSipP8lOO+1srxieQhsNsj6FeN1cpdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059819; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tzO2W+WajMGPZKg0sOd9kLpT7E3B/88XAmc0t2vBAHU=; b=N4Oz76yKzNqQMTP5RQButxF84Fks1we7c/wZq18wp3va3h4krlozVTNkVxhHCFLZFRHNnRC59dltMzsxNO77q2IkvhhjNnwfIUQvoYD8QUU1rRg5CV1j4ixKozFc2BUZ8KxwUet6ON+CH/OFatq4ewkS3wJXfwRUIA5kGX7i5TU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059819295107.9247789785112; Tue, 27 Feb 2024 10:50:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2Ve-0006ac-Kd; Tue, 27 Feb 2024 13:48:58 -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 1rf2Vd-0006Zm-6g for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:57 -0500 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VZ-0001Ve-Oh for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:55 -0500 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6e53f76898fso1210354b3a.0 for ; Tue, 27 Feb 2024 10:48:52 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059731; x=1709664531; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tzO2W+WajMGPZKg0sOd9kLpT7E3B/88XAmc0t2vBAHU=; b=nJ6ZO8FMeMfEoNkbIMVQkx6Gh39+vyaQ4VJBox+JMPRy83EE/xU23mgzqX3eGpeX9u Y4m3MbK1NgPSZIdtqpaBJrhxELAMHRxcVScau7vgbj2BJeeGmrH//P280Lr7MbFDvKKR 3G3kIxP61Ps0oPiA1Cgk1OOTdm40AQXlOCR/gQDQMAUh47D0lSdLiF4xvh/3QnO2oQbn 56E6W+1NCDj9bJeCW2nTOwyuNpuECh9BHXAXfo1e+3Lh9uO3r76waCRAXKQAeUAl73OC T1dRDZkMy5cFEciqC+gwxIpOCJCLT2B8GBiubU1g9LI1s5skTpKWZ0vqqi0ZIIai8DU1 B39w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059731; x=1709664531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tzO2W+WajMGPZKg0sOd9kLpT7E3B/88XAmc0t2vBAHU=; b=CHCz7wPPpXOjMowAOXs2rCNnmwAP2luC4UxOiDVwcDk52sXSJSZ/7+iLerBIDdVEVv rfCJldFJHl2P2C2cdJvJpuc0UsJkVmlO4iMpRPWkrG62WhG/WF5pbeD8+a5EBwrqD+XO zDifb5a7+2Qms8jZ4mhHGDTTUlJZ6J2eKmeifDiAw9vTlBGMmY5BFaiXJ2TcDf9H4gZU eTIjqfamFifBzDrUFZcgRsuMnjPdfR7MP2dTpevuEgJ/Q6X+8oLvoq2bdfLryjwP55Kw B7fRaD/6+5wh5RC7wLqeVGCWbNsgKGMLtkEFicKPG9NoOiENvzfT+SuodyRZ1Oox3/wA IfhA== X-Gm-Message-State: AOJu0Ywr2zsqZliRQujKLG7xSVfYrnIrHZzE6PQWqsZMZc2pvbwA1Jhh SJuZqVmUztPlGD1wdMm10xJKxlPAevnoY7cXZkvMNwfVzZWG+0Q1uU6gVAb2u+pDEZJIP2xBLKT L X-Google-Smtp-Source: AGHT+IFwktXTj333cP6pxP7EV0Ih3RdsH+v8ojIC9qWKCo/Dzqwwl6wVBIG30ZVmYfjBTF1qHxfvdw== X-Received: by 2002:aa7:88d4:0:b0:6e5:456b:bff9 with SMTP id k20-20020aa788d4000000b006e5456bbff9mr4604881pff.12.1709059731642; Tue, 27 Feb 2024 10:48:51 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 11/14] linux-user/elfload: Write process memory to core file in larger chunks Date: Tue, 27 Feb 2024 08:48:30 -1000 Message-Id: <20240227184833.193836-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059821149100001 Content-Type: text/plain; charset="utf-8" We do not need to copy pages from guest memory before writing them out. Because vmas are contiguous in host memory, we can write them in one go. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b8d07d8054..491e754f72 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4551,32 +4551,13 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) } =20 /* - * Finally we can dump process memory into corefile as well. + * Finally write process memory into the corefile as well. */ for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { - abi_ulong addr; - abi_ulong end; + size_t size =3D vma_dump_size(vma); =20 - end =3D vma->vma_start + vma_dump_size(vma); - - for (addr =3D vma->vma_start; addr < end; - addr +=3D TARGET_PAGE_SIZE) { - char page[TARGET_PAGE_SIZE]; - int error; - - /* - * Read in page from target process memory and - * write it to coredump file. - */ - error =3D copy_from_user(page, addr, sizeof (page)); - if (error !=3D 0) { - (void) fprintf(stderr, "unable to dump " TARGET_ABI_FMT_lx= "\n", - addr); - errno =3D -error; - goto out; - } - if (dump_write(fd, page, TARGET_PAGE_SIZE) < 0) - goto out; + if (size && dump_write(fd, g2h_untagged(vma->vma_start), size) < 0= ) { + goto out; } } errno =3D 0; --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059830; cv=none; d=zohomail.com; s=zohoarc; b=UK+xHad9LsVEqAMLcSOvWz6f0ACZv6g1uO2iJ1QbO5S3vTyK9xJs97n/HXTxTqxviKBwkNOPLJdsXKi5nl2ktoklfNhUjQyNl7dDzcz3W8aotAALXJUERkeFkgt8dfNNdMP6INPihhR3WfG/bQPigju9X60pMaXQxM2ZaiG7nCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059830; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HEYpUbYOjLF3aHdvtZVlKWz9YeEEY+0zYSzPOHYy/W8=; b=gpUPJt4tIU0jhljZ/dCe/YKjx3qHKDW2acdOQ6omQO8MgUcBvFGs6s7fRQJ4kitS5Jqlqh2CcQzegwlT9RPDYmewgJTMFcmAB2aiVYl/7WZgkAhrRsH9hdB3ONjB28IjJht+xdLjFeg2d3yoqt8UpZ3r2VqoSl+72sD8BUj8NfE= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059830649768.9109272375032; Tue, 27 Feb 2024 10:50:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2Vf-0006ao-CB; Tue, 27 Feb 2024 13:48:59 -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 1rf2Vd-0006aD-D7 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:57 -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 1rf2Vb-0001Vn-LS for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:57 -0500 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6e125818649so1982519a34.1 for ; Tue, 27 Feb 2024 10:48:53 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059733; x=1709664533; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HEYpUbYOjLF3aHdvtZVlKWz9YeEEY+0zYSzPOHYy/W8=; b=pi2j9o6gBo6MEgj+eyxSTpPgS+q05HwNC4LeS8wRzuLC5k/H+/cgZi0rIbCTxih//j nQyadiGio4UqWp4/swxAknKLr+slvGuBm19KTmg3tQ3g9oUlChqRUnm1d1ooZXA2UF+J HuMgE22ctaV37rergmKORHigd5v+EJ1+IInhwrUA9kf44Qbez1TbD8QdtWuX32raIaYq TdVx/WMItIqUZgG+ArMDllWCHu46eWmvwL0Pkbj01FD6ZYizQfAuZpzFAbGu84QYAAgh oxiCeQ+UucDcKpj6bmww4W2jBSB/dUb0X1MB5DPeL8v1PEECsvy3DU977MGib1bUpoRP xTIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059733; x=1709664533; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HEYpUbYOjLF3aHdvtZVlKWz9YeEEY+0zYSzPOHYy/W8=; b=h4zU6Vnk7NEqePkpp900xEGbkeoh8bwDF3nuI2qL47TNqEacb8432klxas4E8pK5F0 2Qm7I9UP+qTtxIQGkDkst3MMXgw8vqcHcapBnQ32DskfnqYk3jKotcREyrfzl57dx3qC 0oIElwagE9mbvsxsfxD6Pi8oNikTH5NcrZrWIJmRxdxS4CVjXtB5eg4dfqRbvEyr4a/a 0Q8LxxwNgHcP5PWUQYwGzj1DyWvyNCjC1Ii/iNDg3l4z6/0UHpiOBEjeII2ydI5jXrYm UOcYGdW/TaMFgmrsmwGw1K+szBSODl2ne5IrgCWpadz7+/0b+RkuLPyGS6xpThPWg0DO mZZg== X-Gm-Message-State: AOJu0YzdqDTI7WWuMVU/GyVl/NM9Rlh/wAZYi0lQXTAvE7R51fKzCNnA fX6roM1R68b0yO0l82JDlcpHYc/c1R6qVj7p3nxmYqvWxT9lNjtf0E6yhKuTi4ckgWnDE587CL9 1 X-Google-Smtp-Source: AGHT+IEYIIrjmkyuNlJNxPK0XPCoXOM8odFDCkQtFVb3/tRbCR13FnFR1o0hZZXbScIjPusZF2fa/g== X-Received: by 2002:a9d:6d8f:0:b0:6e2:e5a3:1732 with SMTP id x15-20020a9d6d8f000000b006e2e5a31732mr11607472otp.37.1709059732888; Tue, 27 Feb 2024 10:48:52 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 12/14] linux-user/elfload: Simplify vma_dump_size Date: Tue, 27 Feb 2024 08:48:31 -1000 Message-Id: <20240227184833.193836-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::334; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x334.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059831240100001 Content-Type: text/plain; charset="utf-8" Use the flags that we've already saved in order to test accessibility. Use g2h_untagged and compare guest memory directly instead of copy_from_user. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 491e754f72..47b5ce3005 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4166,37 +4166,23 @@ static int vma_get_mapping_count(const struct mm_st= ruct *mm) */ static abi_ulong vma_dump_size(const struct vm_area_struct *vma) { - /* if we cannot even read the first page, skip it */ - if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) - return (0); + /* The area must be readable. */ + if (!(vma->vma_flags & PROT_READ)) { + return 0; + } =20 /* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from - * target library etc. However, thread stacks are marked - * also executable so we read in first page of given region - * and check whether it contains elf header. If there is - * no elf header, we dump it. + * target library etc. If there is no elf header, we dump it. */ - if (vma->vma_flags & PROT_EXEC) { - char page[TARGET_PAGE_SIZE]; - - if (copy_from_user(page, vma->vma_start, sizeof (page))) { - return 0; - } - if ((page[EI_MAG0] =3D=3D ELFMAG0) && - (page[EI_MAG1] =3D=3D ELFMAG1) && - (page[EI_MAG2] =3D=3D ELFMAG2) && - (page[EI_MAG3] =3D=3D ELFMAG3)) { - /* - * Mappings are possibly from ELF binary. Don't dump - * them. - */ - return (0); - } + if (!(vma->vma_flags & PROT_WRITE) && + (vma->vma_flags & PROT_EXEC) && + memcmp(g2h_untagged(vma->vma_start), ELFMAG, SELFMAG) =3D=3D 0) { + return 0; } =20 - return (vma->vma_end - vma->vma_start); + return vma->vma_end - vma->vma_start; } =20 static int vma_walker(void *priv, target_ulong start, target_ulong end, --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059859; cv=none; d=zohomail.com; s=zohoarc; b=KNvHZLdB67dgfc5+8j8GYIX/YR2oc/+iwqmFTuNJqI7ss4Wl3YgqXl3OybpTB1JFFhfEd4UszLelIQxngz/MMQ0IPMlymroinD0n3GiUfm3Np0e1PsemGws/UXwTSbpktODXR6elmu9qObX2z1HIx0bAQutnj8I7PaM5jpLVlpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059859; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mVP5ZXMph2vIaMrgjNZyRxPQx2YhCwiWw0i2ONELss0=; b=UXQGuzY65Tih2cEPRrGK7XwL3xsnRpKTMgqRO/6ogwy2Y0McwEF+/XZe2+1prB5Hj5on+AOoXyu2k9SIzJ7DY1kzFak+qWS5oEl90AZSHgb+k1jq04etOR3PQMhQnotlRGToi7G+rOSMGWS+89aP22gPy/6jJTqjOx72lTy9gvQ= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059859333818.5820397821213; Tue, 27 Feb 2024 10:50:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2Vh-0006bp-9V; Tue, 27 Feb 2024 13:49:01 -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 1rf2Vf-0006at-3N for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:59 -0500 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2Vc-0001W6-Df for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:58 -0500 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6e435542d41so3144896b3a.1 for ; Tue, 27 Feb 2024 10:48:55 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059734; x=1709664534; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mVP5ZXMph2vIaMrgjNZyRxPQx2YhCwiWw0i2ONELss0=; b=jUonchxBXfrSUgZCvU/gMSmnrOX8R+aToUhjCvv+aKLMma35dd4WNy1SQnxbb+Yzoo wWroeel3cAnOVXDM7BnfNf0cyGlK1Hi0SDkC5MZbJr9DsaLwWre30wch95vhMpsTpOCO 3K2RKSAPykzeVT8fp9jRujiKTfAXGEX2nsxpeZF/y3B//FHXz8j/wO8gNmahl5G6Yv/T QNWasrvLHjkoVXyVMeKOmGgBzU95PirffRSNB1y3aGLp5u2TsM9ReO9r5zpmI4XhqR0y Q3zKRctNZiESXfG0boE9xVgZrwJSVCD4k0Aman6UF2hm72vyQ1b762/ipjZZa8zOcpJ1 czZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059734; x=1709664534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mVP5ZXMph2vIaMrgjNZyRxPQx2YhCwiWw0i2ONELss0=; b=KcOcSykjbbjROfn6/uEpqFOLitB5EgC/0PfEGPwvKjP2Ih77lLfrEjCy4w2k+wyjCr 0PxcoJqcpimo6kxHwDL0/XcAT35YGoo1QOLoWbRpthDVUzOLXu7YSIsHUAuz7lug8lqb 4w1pv42WKGPMzAzehkYnkMq/UTqqvKrq59Ak2v8EtaJwD7NO0di5q7csy2UialsDFiSR q2/n3syh9nzlqpBNZT57+RiDDpzqC/Zl4GUuuE2Um2gm8/JovQwXQ7L/MxrxSLu2v9PA W5Fz+HrLoeZ6TWIsRH7KyFU6Fs6ZX0A6oXmYZ5rsJZ2N8x+8h5oqbLW/GcF/eorNlbxR +5Cw== X-Gm-Message-State: AOJu0Yy19uirgv0wLdKEhsyG34MceaatDNysU5fBUEvNEwp2eYoiUO9O 0jLL1qi1Tqy7IvrlvXNGOOJhQ43VLbV4n0sVcYUhqKjagJWB9yHt8Wb9qswFjsWnzoH3wMOAeGQ G X-Google-Smtp-Source: AGHT+IG3YxJfLjCHbKg5/1vujJkbfQ9aeAmCAeauWlz6fvOGadlc+Qwdve8vlJFO42irzafhzJuPZw== X-Received: by 2002:a05:6a00:1ac7:b0:6e4:d198:6d66 with SMTP id f7-20020a056a001ac700b006e4d1986d66mr13089692pfv.7.1709059734358; Tue, 27 Feb 2024 10:48:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 13/14] linux-user/elfload: Rely on walk_memory_regions for vmas Date: Tue, 27 Feb 2024 08:48:32 -1000 Message-Id: <20240227184833.193836-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059861327100011 Content-Type: text/plain; charset="utf-8" Rather than creating new data structures for vma, rely on the IntervalTree used by walk_memory_regions. Use PAGE_* constants, per the page table api, rather than PROT_* constants, per the mmap api. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 213 ++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 135 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 47b5ce3005..ae0abc4931 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4041,29 +4041,6 @@ struct target_elf_prpsinfo { char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ }; =20 -struct vm_area_struct { - target_ulong vma_start; /* start vaddr of memory region */ - target_ulong vma_end; /* end vaddr of memory region */ - abi_ulong vma_flags; /* protection etc. flags for the region */ - QTAILQ_ENTRY(vm_area_struct) vma_link; -}; - -struct mm_struct { - QTAILQ_HEAD(, vm_area_struct) mm_mmap; - int mm_count; /* number of mappings */ -}; - -static void vma_init(struct mm_struct *); -static void vma_delete(struct mm_struct *); -static int vma_add_mapping(struct mm_struct *, target_ulong, - target_ulong, abi_ulong); -static int vma_get_mapping_count(const struct mm_struct *); -static struct vm_area_struct *vma_first(const struct mm_struct *); -static struct vm_area_struct *vma_next(struct vm_area_struct *); -static abi_ulong vma_dump_size(const struct vm_area_struct *); -static int vma_walker(void *priv, target_ulong start, target_ulong end, - unsigned long flags); - #ifdef BSWAP_NEEDED static void bswap_prstatus(struct target_elf_prstatus *prstatus) { @@ -4105,69 +4082,14 @@ static inline void bswap_psinfo(struct target_elf_p= rpsinfo *p) {} static inline void bswap_note(struct elf_note *en) { } #endif /* BSWAP_NEEDED */ =20 -/* - * Minimal support for linux memory regions. These are needed - * when we are finding out what memory exactly belongs to - * emulated process. No locks needed here, as long as - * thread that received the signal is stopped. - */ - -static void vma_init(struct mm_struct *mm) -{ - mm->mm_count =3D 0; - QTAILQ_INIT(&mm->mm_mmap); -} - -static void vma_delete(struct mm_struct *mm) -{ - struct vm_area_struct *vma; - - while ((vma =3D vma_first(mm)) !=3D NULL) { - QTAILQ_REMOVE(&mm->mm_mmap, vma, vma_link); - g_free(vma); - } -} - -static int vma_add_mapping(struct mm_struct *mm, target_ulong start, - target_ulong end, abi_ulong flags) -{ - struct vm_area_struct *vma; - - if ((vma =3D g_malloc0(sizeof (*vma))) =3D=3D NULL) - return (-1); - - vma->vma_start =3D start; - vma->vma_end =3D end; - vma->vma_flags =3D flags; - - QTAILQ_INSERT_TAIL(&mm->mm_mmap, vma, vma_link); - mm->mm_count++; - - return (0); -} - -static struct vm_area_struct *vma_first(const struct mm_struct *mm) -{ - return (QTAILQ_FIRST(&mm->mm_mmap)); -} - -static struct vm_area_struct *vma_next(struct vm_area_struct *vma) -{ - return (QTAILQ_NEXT(vma, vma_link)); -} - -static int vma_get_mapping_count(const struct mm_struct *mm) -{ - return (mm->mm_count); -} - /* * Calculate file (dump) size of given memory region. */ -static abi_ulong vma_dump_size(const struct vm_area_struct *vma) +static size_t vma_dump_size(target_ulong start, target_ulong end, + unsigned long flags) { /* The area must be readable. */ - if (!(vma->vma_flags & PROT_READ)) { + if (!(flags & PAGE_READ)) { return 0; } =20 @@ -4176,22 +4098,13 @@ static abi_ulong vma_dump_size(const struct vm_area= _struct *vma) * non-writable code that debugger can read directly from * target library etc. If there is no elf header, we dump it. */ - if (!(vma->vma_flags & PROT_WRITE) && - (vma->vma_flags & PROT_EXEC) && - memcmp(g2h_untagged(vma->vma_start), ELFMAG, SELFMAG) =3D=3D 0) { + if (!(flags & PAGE_WRITE_ORG) && + (flags & PAGE_EXEC) && + memcmp(g2h_untagged(start), ELFMAG, SELFMAG) =3D=3D 0) { return 0; } =20 - return vma->vma_end - vma->vma_start; -} - -static int vma_walker(void *priv, target_ulong start, target_ulong end, - unsigned long flags) -{ - struct mm_struct *mm =3D (struct mm_struct *)priv; - - vma_add_mapping(mm, start, end, flags); - return (0); + return end - start; } =20 static size_t size_note(const char *name, size_t datasz) @@ -4367,6 +4280,61 @@ static int dump_write(int fd, const void *ptr, size_= t size) return (0); } =20 +typedef struct { + unsigned count; + size_t size; +} CountAndSizeRegions; + +static int wmr_count_and_size_regions(void *opaque, target_ulong start, + target_ulong end, unsigned long flag= s) +{ + CountAndSizeRegions *css =3D opaque; + + css->count++; + css->size +=3D vma_dump_size(start, end, flags); + return 0; +} + +typedef struct { + struct elf_phdr *phdr; + off_t offset; +} FillRegionPhdr; + +static int wmr_fill_region_phdr(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + FillRegionPhdr *d =3D opaque; + struct elf_phdr *phdr =3D d->phdr; + + phdr->p_type =3D PT_LOAD; + phdr->p_vaddr =3D start; + phdr->p_paddr =3D 0; + phdr->p_filesz =3D vma_dump_size(start, end, flags); + phdr->p_offset =3D d->offset; + d->offset +=3D phdr->p_filesz; + phdr->p_memsz =3D end - start; + phdr->p_flags =3D (flags & PAGE_READ ? PF_R : 0) + | (flags & PAGE_WRITE_ORG ? PF_W : 0) + | (flags & PAGE_EXEC ? PF_X : 0); + phdr->p_align =3D ELF_EXEC_PAGESIZE; + + bswap_phdr(phdr, 1); + d->phdr =3D phdr + 1; + return 0; +} + +static int wmr_write_region(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + int fd =3D *(int *)opaque; + size_t size =3D vma_dump_size(start, end, flags); + + if (!size) { + return 0; + } + return dump_write(fd, g2h_untagged(start), size); +} + /* * Write out ELF coredump. * @@ -4414,12 +4382,11 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) { const CPUState *cpu =3D env_cpu((CPUArchState *)env); const TaskState *ts =3D (const TaskState *)cpu->opaque; - struct vm_area_struct *vma; struct rlimit dumpsize; - struct mm_struct mm; + CountAndSizeRegions css; off_t offset, note_offset, data_offset; size_t note_size; - int segs, cpus, ret; + int cpus, ret; int fd =3D -1; CPUState *cpu_iter; =20 @@ -4438,9 +4405,8 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) * Walk through target process memory mappings and * set up structure containing this information. */ - vma_init(&mm); - walk_memory_regions(&mm, vma_walker); - segs =3D vma_get_mapping_count(&mm); + memset(&css, 0, sizeof(css)); + walk_memory_regions(&css, wmr_count_and_size_regions); =20 cpus =3D 0; CPU_FOREACH(cpu_iter) { @@ -4448,22 +4414,18 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) } =20 offset =3D sizeof(struct elfhdr); - offset +=3D (segs + 1) * sizeof(struct elf_phdr); + offset +=3D (css.count + 1) * sizeof(struct elf_phdr); note_offset =3D offset; =20 offset +=3D size_note("CORE", ts->info->auxv_len); offset +=3D size_note("CORE", sizeof(struct target_elf_prpsinfo)); offset +=3D size_note("CORE", sizeof(struct target_elf_prstatus)) * cp= us; note_size =3D offset - note_offset; - offset =3D ROUND_UP(offset, ELF_EXEC_PAGESIZE); - data_offset =3D offset; - - for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { - offset +=3D vma_dump_size(vma); - } + data_offset =3D ROUND_UP(offset, ELF_EXEC_PAGESIZE); =20 /* Do not dump if the corefile size exceeds the limit. */ - if (dumpsize.rlim_cur !=3D RLIM_INFINITY && dumpsize.rlim_cur < offset= ) { + if (dumpsize.rlim_cur !=3D RLIM_INFINITY + && dumpsize.rlim_cur < data_offset + css.size) { errno =3D 0; goto out; } @@ -4485,36 +4447,22 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) */ { g_autofree void *header =3D g_malloc0(data_offset); + FillRegionPhdr frp; void *hptr, *dptr; =20 /* Create elf file header. */ hptr =3D header; - fill_elf_header(hptr, segs + 1, ELF_MACHINE, 0); + fill_elf_header(hptr, css.count + 1, ELF_MACHINE, 0); hptr +=3D sizeof(struct elfhdr); =20 /* Create elf program headers. */ fill_elf_note_phdr(hptr, note_size, note_offset); hptr +=3D sizeof(struct elf_phdr); =20 - offset =3D data_offset; - for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma))= { - struct elf_phdr *phdr =3D hptr; - - phdr->p_type =3D PT_LOAD; - phdr->p_offset =3D offset; - phdr->p_vaddr =3D vma->vma_start; - phdr->p_paddr =3D 0; - phdr->p_filesz =3D vma_dump_size(vma); - offset +=3D phdr->p_filesz; - phdr->p_memsz =3D vma->vma_end - vma->vma_start; - phdr->p_flags =3D (vma->vma_flags & PROT_READ ? PF_R : 0) - | (vma->vma_flags & PROT_WRITE ? PF_W : 0) - | (vma->vma_flags & PROT_EXEC ? PF_X : 0); - phdr->p_align =3D ELF_EXEC_PAGESIZE; - - bswap_phdr(phdr, 1); - hptr +=3D sizeof(struct elf_phdr); - } + frp.phdr =3D hptr; + frp.offset =3D data_offset; + walk_memory_regions(&frp, wmr_fill_region_phdr); + hptr =3D frp.phdr; =20 /* Create the notes. */ dptr =3D fill_note(&hptr, NT_AUXV, "CORE", ts->info->auxv_len); @@ -4539,12 +4487,8 @@ static int elf_core_dump(int signr, const CPUArchSta= te *env) /* * Finally write process memory into the corefile as well. */ - for (vma =3D vma_first(&mm); vma !=3D NULL; vma =3D vma_next(vma)) { - size_t size =3D vma_dump_size(vma); - - if (size && dump_write(fd, g2h_untagged(vma->vma_start), size) < 0= ) { - goto out; - } + if (walk_memory_regions(&fd, wmr_write_region) < 0) { + goto out; } errno =3D 0; =20 @@ -4552,7 +4496,6 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) ret =3D -errno; mmap_unlock(); cpu_list_unlock(); - vma_delete(&mm); close(fd); return ret; } --=20 2.34.1 From nobody Tue Nov 26 06:58:52 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=1709059770; cv=none; d=zohomail.com; s=zohoarc; b=A6gRVw5XzpNT6atsUKgGGgGxY3FS+9LG1leDtEBAXOHyv4B+G6I/Svm7dQF+Zs6e8qKtkyr0qGgginJZYxjFo2bxG7/17SlUdon5IRjs8zGWKoRT/Ow+Ex245QVpq05EDjJtoxkd+jeDffX8uD7PHPj99lyKnuq2YdpqRFbQ/gE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059770; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=Kpxz1/9FlWlIVji+Er2Ytuv2fi+3FqVKlI4/eYDV3CGG/rqvmVzdxB0C7J4c/X8OwBSeFec+8h5/Nejellsr9GBu9GOcNaOPraZfXYy4xnktm/c/ji5wlXOtLF8DYzBfTkA+6m8Mu/OiZOd/CTVlZSxB6uH2aDYryU2q3rei4/k= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709059769995567.7077690763789; Tue, 27 Feb 2024 10:49:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2Vh-0006bt-LO; Tue, 27 Feb 2024 13:49:01 -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 1rf2Vg-0006bT-Eg for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:49:00 -0500 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2Ve-0001WI-3p for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:49:00 -0500 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3c19bc08f96so2645678b6e.2 for ; Tue, 27 Feb 2024 10:48:57 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059735; x=1709664535; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=bk2bEhaspsIlDdm37ktyEla0/+/heZjF5/vny1ifWJlHAJ4L76lWvtpPdBmnKaKpKB y93Rwe8e3yo+OVJnX2uvyZiP2V3AMqI6rPAHLLGcsqJn93UHXY5KYxBX79yBsb7rhjAs S3iSOH8VBJdJ3rLqHCgEPqsDtr8phsbwLdVtkOqjWl8OEFQ9aF2Uhq/bQoHj7DKqECZr BH89+pweLb/GdaS2rDClziAFdwxZaCI0NiK89QcNmJ8+CltCWKWa4oQe3Y6AxGcIV4EJ jFNOAGfdYQRKB+brsZSs9+38o9/R0AE4LN3Y153ph5dtydkKdWtzckm/pvhICPu/y9Td Qzrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059735; x=1709664535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=jKWh3n0MWM7CajGpKSOagmyThxoGV8gc5jSyMwTuIxjW4kcLyrHS7T7Yh3bXLXJDef A35UExPfa5UX6DfxdwmXwdKCG2d7fttv5o86JDE4+Eljsibup/Z6wNdskr0z2xlme8xD oJLAMkFGEitC60z0SesXZunPzpe96dSR7F7b9IdyxD7frQg+fEMbCIm8WaLGM5LSFt8w i/sNRiPDvpsl14hr8YkiZlb9aesq0O6Lo1aDilkI8WGTUJ35/Ra1fUMCh7J2tuhqdhOB XU6Hq4fOj7SDKlwkydl5PjPGVlKZQFUIOuNKr7U78Q4BLHgzeDjrseqc41/+Kk/qXuAE IQGg== X-Gm-Message-State: AOJu0YxGKXBBElc4pFs0IuiFd20RI2qMGt9shsxs1eZUXuyaYi1zKW03 7WL9fMpJTxzdsoCrXLvOWdf8zCZNU2ksrpAWjj2bcKiuSvxrncylamGRf6iwGDGIHYEp82QxMJF P X-Google-Smtp-Source: AGHT+IFwPv20Lunhw0EIl5D610KWJyC2ViJkG+Z2W8wOQe0dzYY6wDqca/yIh4a4kGNXtITZ/38aLg== X-Received: by 2002:a05:6808:14c7:b0:3bf:bf81:c700 with SMTP id f7-20020a05680814c700b003bfbf81c700mr3445815oiw.16.1709059735654; Tue, 27 Feb 2024 10:48:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 14/14] linux-user/elfload: Unprotect regions before core dump Date: Tue, 27 Feb 2024 08:48:33 -1000 Message-Id: <20240227184833.193836-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> 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::235; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x235.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059771871100001 Content-Type: text/plain; charset="utf-8" By unprotecting regions, we re-instate writability and unify regions that have been split, which may reduce the total number of regions. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ae0abc4931..38bfc9ac67 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3963,6 +3963,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) } =20 #ifdef USE_ELF_CORE_DUMP +#include "exec/translate-all.h" + /* * Definitions to generate Intel SVR4-like core files. * These mostly have the same names as the SVR4 types with "target_elf_" @@ -4280,6 +4282,23 @@ static int dump_write(int fd, const void *ptr, size_= t size) return (0); } =20 +static int wmr_page_unprotect_regions(void *opaque, target_ulong start, + target_ulong end, unsigned long flag= s) +{ + if ((flags & (PAGE_WRITE | PAGE_WRITE_ORG)) =3D=3D PAGE_WRITE_ORG) { + size_t step =3D MAX(TARGET_PAGE_SIZE, qemu_host_page_size); + + while (1) { + page_unprotect(start, 0); + if (end - start <=3D step) { + break; + } + start +=3D step; + } + } + return 0; +} + typedef struct { unsigned count; size_t size; @@ -4401,6 +4420,9 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) cpu_list_lock(); mmap_lock(); =20 + /* By unprotecting, we merge vmas that might be split. */ + walk_memory_regions(NULL, wmr_page_unprotect_regions); + /* * Walk through target process memory mappings and * set up structure containing this information. --=20 2.34.1