From nobody Wed Nov 27 07:42:24 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 ARC-Seal: i=1; a=rsa-sha256; t=1700066307; cv=none; d=zohomail.com; s=zohoarc; b=QqHZd8MsgJn4BtY0ehgoU6I+LLHgRXSqKoFVo3Ddvt9D8ndQrU8q0Rj7WNILQtFJH5FG2rv1Fwidwav1tsaqOu4E1cMgoVGdDYTOz3wTRL+c6d0F+C1uyPgHOrUhW7oLjFgSxVEkR2FGECYDjV7kwn8oH80O+4tpDS9xnvBBKv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700066307; h=Content-Type: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=xhIaYCwM/yHHLfANkRsUChGAK3y6AbqzaTehROnBZak=; b=L7kqfS0D/ljHOu6GcYH1/lVGGpPtf3yJwPnqyaa3zEs/KTl250MgDkL/HlsHSt1RCn9NV8Ugu8iriTGAfQJ25xgN7ySUd/I/+FQWnVOEzT+VGHYlFOc1ek0ty+RRza4fAfRBG54pHE+inyXT3fEKdkAcBDwlGU1wlVxdf9ALlFI= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700066306837816.4242707729911; Wed, 15 Nov 2023 08:38:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3Itu-0006UI-4U; Wed, 15 Nov 2023 11:38:02 -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 1r3Itr-0006Th-RY for qemu-devel@nongnu.org; Wed, 15 Nov 2023 11:37:59 -0500 Received: from todd.t-8ch.de ([159.69.126.157]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3Itj-0000ra-LT for qemu-devel@nongnu.org; Wed, 15 Nov 2023 11:37:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1700066266; bh=CL1tBmJdfg1o8X6S56EaYxtC620ylQ9H8523erZVxT8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OoerHE6/lAcRbS2hsnyyBQe1airLoKE3PqHY+f+i1lKeQPOBgRSuZ7Lv8ZjaSvyoj TGiG2b5wGN6lG4IvBTwrLyOfiSkpZm0XtDZi0NuWjWK7jBI0GfK4v8LF4UZg2bC/ig Oqt3QcGRpYTHft2zDs9oIT+5Q+cCkiP6D63iLh1Q= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 15 Nov 2023 17:37:39 +0100 Subject: [PATCH 1/2] linux-user/elfload: test return value of getrlimit MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231115-qemu-user-dumpable-v1-1-edbe7f0fbb02@t-8ch.de> References: <20231115-qemu-user-dumpable-v1-0-edbe7f0fbb02@t-8ch.de> In-Reply-To: <20231115-qemu-user-dumpable-v1-0-edbe7f0fbb02@t-8ch.de> To: Laurent Vivier Cc: qemu-devel@nongnu.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700066266; l=813; i=thomas@t-8ch.de; s=20221212; h=from:subject:message-id; bh=CL1tBmJdfg1o8X6S56EaYxtC620ylQ9H8523erZVxT8=; b=0HrJ/EWHOum6ZLS6xk8GM17P8lDyCv2RJTEaubLBoCg7KWQxj2KrOvvWj7ltb7VUfzxcM/hmq 7VBI2cwz/37AJgbVu+d3rQU3IW7RmihfN+TNJgaSgHe+xs0Y7vYXWTQ X-Developer-Key: i=thomas@t-8ch.de; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= 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=159.69.126.157; envelope-from=thomas@t-8ch.de; helo=todd.t-8ch.de 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, 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 @t-8ch.de) X-ZM-MESSAGEID: 1700066309144100001 Should getrlimit() fail the value of dumpsize.rlimit_cur may not be initialized. Avoid reading garbage data by checking the return value of getrlimit. Signed-off-by: Thomas Wei=C3=9Fschuh --- linux-user/elfload.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 4cd6891d7b6a..799fe8497346 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4667,8 +4667,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) init_note_info(&info); =20 errno =3D 0; - getrlimit(RLIMIT_CORE, &dumpsize); - if (dumpsize.rlim_cur =3D=3D 0) + if (getrlimit(RLIMIT_CORE, &dumpsize) =3D=3D 0 && dumpsize.rlim_cur = =3D=3D 0) return 0; =20 corefile =3D core_dump_filename(ts); --=20 2.42.1 From nobody Wed Nov 27 07:42:24 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 ARC-Seal: i=1; a=rsa-sha256; t=1700066308; cv=none; d=zohomail.com; s=zohoarc; b=ciA7TtFFSIyU0f56RcvNHheeCdURIPLnIQ0vta21nd7gYWYs9+n123mRzsAlgEFJiAQLuSTu8dv9FoCnw9qywgqqhkKnL2F16GBVQD/JzVZ4HuzwJbB9lGZ13DsNEKGcgaCWXX7YBdoIMX8lYy45gGXxx0b6WXarkuZMv2VLYa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700066308; h=Content-Type: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=LWIh/6yotY4vI7/gSoATBeVv5H24Sbe5jwQ5/35dItg=; b=Pyl4A+zP+FGbjNUK0bUBw5dOjUH+q3zXGDbRvSzsjCrfZE6NFMn9hQydkCC8A3VdxaOEydpxs+6ibCR+QF+g6hM9VpJ0Wyzb3xhaQxjSWaCIWXT8x64+7AzXIwhmOGfkcWOLRtUbRyzJINyzCvR6UDIzxU5tx2viJ+//jBafOYA= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700066308125792.5740533503784; Wed, 15 Nov 2023 08:38:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3Itw-0006UN-0Q; Wed, 15 Nov 2023 11:38:04 -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 1r3Its-0006Tq-D5 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 11:38:00 -0500 Received: from todd.t-8ch.de ([159.69.126.157]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3Itm-0000rb-Vq for qemu-devel@nongnu.org; Wed, 15 Nov 2023 11:37:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1700066266; bh=qxXamQTO5EoE2my1lcK0XNmqaLU9AUm9JbNb0ypAEuY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=H+nCyvZWXC8DfAICmjWTxZgJ0eIhabUNWs3LBEFi2yk0VOv/n07Db9glL9SjBEegH nWZrFL3XQyPYB7+n+r5NXml/gI4QKrgt7tPULmqZa8McUuG2RtinXkDtUNKwY07KQW 1sGgxe3YX6FVSVB5XXsZ4sJftx53y3s11TO0cdA0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 15 Nov 2023 17:37:40 +0100 Subject: [PATCH 2/2] linux-user/elfload: check PR_GET_DUMPABLE before creating coredump MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231115-qemu-user-dumpable-v1-2-edbe7f0fbb02@t-8ch.de> References: <20231115-qemu-user-dumpable-v1-0-edbe7f0fbb02@t-8ch.de> In-Reply-To: <20231115-qemu-user-dumpable-v1-0-edbe7f0fbb02@t-8ch.de> To: Laurent Vivier Cc: qemu-devel@nongnu.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700066266; l=1019; i=thomas@t-8ch.de; s=20221212; h=from:subject:message-id; bh=qxXamQTO5EoE2my1lcK0XNmqaLU9AUm9JbNb0ypAEuY=; b=DF52vlE2rNj9bhBR1JyAnsc85yatvg5Ys2ohKEFJ74EYMNKDMqmcI5FfbXqeaYsY90tJkszPz I2UYlRTKo/aBg/EtrSrmZ3bN8HOGMt/NLKZfw5TrukCkP6UZH6YC43i X-Developer-Key: i=thomas@t-8ch.de; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= 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=159.69.126.157; envelope-from=thomas@t-8ch.de; helo=todd.t-8ch.de 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, 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 @t-8ch.de) X-ZM-MESSAGEID: 1700066309795100009 A process can opt-out of coredump creation by calling prctl(PR_SET_DUMPABLE, 0). linux-user passes this call from the guest through to the operating system. From there it can be read back again to avoid creating coredumps from qemu-user itself if the guest chose so. Signed-off-by: Thomas Wei=C3=9Fschuh --- linux-user/elfload.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 799fe8497346..76d5740af0ca 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2,6 +2,7 @@ #include "qemu/osdep.h" #include =20 +#include #include #include =20 @@ -4667,6 +4668,10 @@ static int elf_core_dump(int signr, const CPUArchSta= te *env) init_note_info(&info); =20 errno =3D 0; + + if (prctl(PR_GET_DUMPABLE) =3D=3D 0) + return 0; + if (getrlimit(RLIMIT_CORE, &dumpsize) =3D=3D 0 && dumpsize.rlim_cur = =3D=3D 0) return 0; =20 --=20 2.42.1