From nobody Mon May 20 17:29:56 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1683750511; cv=none; d=zohomail.com; s=zohoarc; b=BJdNGYNVZFG/BPyx1RXloZH5rT/ztjv1nhg9DmmMHLsLO1HrjxZBBkg96N7WQeYuku1nxRuX4wHqYYi34kqK+8xpYQh5H/z91H8f/25938mJGkbKqZCkqhb6UC5GHZ4gyfqs+BegLpGRZH/HGPnpB/IfZ2byjXvfVFkvLZcFNEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683750511; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mjevnpD3EKrB/U+ToMob3mWZQ0lrXW36lyqz0JHpToo=; b=Y+ZXue50MN4j10wIzUAdnPP9XQB6/OD+l/rwpH738AB3uyOkqATuKuEFvOzy8uSb6IXPVGeKvBQC1IWJCTIfM37EMNER2kfz4A+TrmokZaDj2y5yUsoEG9nb2WZkX1oSX/CP1eatH8l6/iyP3KGu8Jd4HPQp7snBFo4tHaJafUQ= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683750511981518.7916707219131; Wed, 10 May 2023 13:28:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqPA-0000IB-2a; Wed, 10 May 2023 16:27:20 -0400 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 1pwqP7-0000HL-PE for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqP5-0000zb-2m for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:17 -0400 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AKKcSG005129; Wed, 10 May 2023 20:27:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgbgm5vda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:11 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34AK7PU8011229; Wed, 10 May 2023 20:27:10 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgbgm5vbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:10 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34AI7UmE015404; Wed, 10 May 2023 20:27:08 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3qf7d1s1h2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:07 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34AKR4RU39191116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 May 2023 20:27:04 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 42C1E2004B; Wed, 10 May 2023 20:27:04 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B0EC920040; Wed, 10 May 2023 20:27:03 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.51.237]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 May 2023 20:27:03 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=mjevnpD3EKrB/U+ToMob3mWZQ0lrXW36lyqz0JHpToo=; b=iLGyIZ7KMvyb/Lh87qatWYCE6UJ3XUxDKRRyX1KYwpc7nw1uRm0hp4edGm4nhOKit6ea HsOCyVrb6FIzlllL5zAa9uqyBzF2bVkXs0PmBJlBYlMdu9csn7+H88czQHmp5jL2W6Xt VMO4SxjtdnZgx+IKFVj5FMlywnmRmcOsJ1SNy/eI3PI3XxS9X67Iy1aDRyRzONhHK7Dt 3I9sv8cMcN0bCu76EWYqgjPcaMhU2pJ4dJngJNfbt/P/gGKCmhchDhlRGwvY1Kafs6kq Rr2PwZSuuCkUNn9ECoSa2dJZHQ1FzYrITJvjBNbVCA+9BEct1jS+tWJY9l45y/7uQ9e1 Yw== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Cc: "Dominik 'Disconnect3d' Czarnota" , Christian Borntraeger , Andreas Arnez , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH RESEND 1/6] linux-user: Expose do_guest_openat() and do_guest_readlink() Date: Wed, 10 May 2023 22:26:49 +0200 Message-Id: <20230510202654.225689-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510202654.225689-1-iii@linux.ibm.com> References: <20230510202654.225689-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: -hK2nzvt_KpMoyqzHDtsS2xZmitgn8GN X-Proofpoint-ORIG-GUID: fNFsc5j8_s5hy51rA78MmZVjGQN4Hjjq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 phishscore=0 impostorscore=0 bulkscore=0 spamscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100163 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=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1683750512440100003 Content-Type: text/plain; charset="utf-8" These functions will be required by the GDB stub in order to provide the guest view of /proc to GDB. Signed-off-by: Ilya Leoshkevich Reviewed-by: Alex Benn=C3=A9e --- linux-user/qemu.h | 3 +++ linux-user/syscall.c | 54 ++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index e2e93fbd1d5..08bcdd7b7c5 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -165,6 +165,9 @@ typedef struct TaskState { } TaskState; =20 abi_long do_brk(abi_ulong new_brk); +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + int flags, mode_t mode); +ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz); =20 /* user access */ =20 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 69f740ff98c..80dbcfec426 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8317,7 +8317,8 @@ static int open_hardware(CPUArchState *cpu_env, int f= d) } #endif =20 -static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathnam= e, int flags, mode_t mode) +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + int flags, mode_t mode) { struct fake_open { const char *filename; @@ -8388,6 +8389,36 @@ static int do_openat(CPUArchState *cpu_env, int dirf= d, const char *pathname, int return safe_openat(dirfd, path(pathname), flags, mode); } =20 +ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz) +{ + ssize_t ret; + + if (!pathname || !buf) { + errno =3D EFAULT; + return -1; + } + + if (!bufsiz) { + /* Short circuit this for the magic exe check. */ + errno =3D EINVAL; + return -1; + } + + if (is_proc_myself((const char *)pathname, "exe")) { + /* + * Don't worry about sign mismatch as earlier mapping + * logic would have thrown a bad address error. + */ + ret =3D MIN(strlen(exec_path), bufsiz); + /* We cannot NUL terminate the string. */ + memcpy(buf, exec_path, ret); + } else { + ret =3D readlink(path(pathname), buf, bufsiz); + } + + return ret; +} + static int do_execveat(CPUArchState *cpu_env, int dirfd, abi_long pathname, abi_long guest_argp, abi_long guest_envp, int flags) @@ -8850,7 +8881,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, in= t num, abi_long arg1, case TARGET_NR_open: if (!(p =3D lock_user_string(arg1))) return -TARGET_EFAULT; - ret =3D get_errno(do_openat(cpu_env, AT_FDCWD, p, + ret =3D get_errno(do_guest_openat(cpu_env, AT_FDCWD, p, target_to_host_bitmask(arg2, fcntl_flags= _tbl), arg3)); fd_trans_unregister(ret); @@ -8860,7 +8891,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, in= t num, abi_long arg1, case TARGET_NR_openat: if (!(p =3D lock_user_string(arg2))) return -TARGET_EFAULT; - ret =3D get_errno(do_openat(cpu_env, arg1, p, + ret =3D get_errno(do_guest_openat(cpu_env, arg1, p, target_to_host_bitmask(arg3, fcntl_flags= _tbl), arg4)); fd_trans_unregister(ret); @@ -10031,22 +10062,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env,= int num, abi_long arg1, void *p2; p =3D lock_user_string(arg1); p2 =3D lock_user(VERIFY_WRITE, arg2, arg3, 0); - if (!p || !p2) { - ret =3D -TARGET_EFAULT; - } else if (!arg3) { - /* Short circuit this for the magic exe check. */ - ret =3D -TARGET_EINVAL; - } else if (is_proc_myself((const char *)p, "exe")) { - /* - * Don't worry about sign mismatch as earlier mapping - * logic would have thrown a bad address error. - */ - ret =3D MIN(strlen(exec_path), arg3); - /* We cannot NUL terminate the string. */ - memcpy(p2, exec_path, ret); - } else { - ret =3D get_errno(readlink(path(p), p2, arg3)); - } + ret =3D get_errno(do_guest_readlink(p, p2, arg3)); unlock_user(p2, arg2, ret); unlock_user(p, arg1, 0); } --=20 2.40.1 From nobody Mon May 20 17:29:56 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1683750510; cv=none; d=zohomail.com; s=zohoarc; b=OzPbLBJOqIQn/TQY+gPJC3EXnWWmiE38N1HpboZUF32bsB3gBiVM3e697uFEhEFEWsy/XqD9ByWWT2w8ti5dBwd5mfRnl4kIEcN41VYQWn9iWV10wgCPzGzu4kFvo72n9H+pHyVuvSJUpSnFVGUXFPY2dMlAFN2zd/9ay1/01fQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683750510; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I4QyKzOLDbj0XvCzrjMdQaeptjBkpecKuuxTLMoB7VM=; b=OkSxZpNESGfXDs+IIQu8f4K5OHwtDIBRPBL2TfoXJlDEN8n6YKFTb4qZ31NvtCyurADGsq4rnP+C8uJy6E7oyWV6lRjbitaHZWy0vqYPpiJHgOYGZXfizAQJ4drRibDXqg8ank5fu2dJKPXsYjKOdIfgMWj8ePiqKnH1mZDec1w= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168375051049183.5569173884279; Wed, 10 May 2023 13:28:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqP8-0000Hb-Ta; Wed, 10 May 2023 16:27:18 -0400 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 1pwqP6-0000Gy-BK for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:16 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqP4-0000zY-FY for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:16 -0400 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AK9L5w017364; Wed, 10 May 2023 20:27:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduud0f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:11 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34AKMdoJ031733; Wed, 10 May 2023 20:27:11 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduucy3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:10 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34AK99WP027064; Wed, 10 May 2023 20:27:09 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0s1ff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:09 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34AKR5PC50594230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 May 2023 20:27:05 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B27C20040; Wed, 10 May 2023 20:27:05 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9D5E20043; Wed, 10 May 2023 20:27:04 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.51.237]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 May 2023 20:27:04 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=I4QyKzOLDbj0XvCzrjMdQaeptjBkpecKuuxTLMoB7VM=; b=DWGbOeA5ykewHYlPHxbHggHbfvNk2f/Pnh+lHYOmTc/OrmCxwCjnhcqT8XC28Ax+GHw7 vu4XGegCAlUU8CfzwyvDvVPrYfqO1J+QN2VdEKzIkOfeSUhQ1teiJaewUYNDLHWQf/sk aK3qRK/cY7BSMLbgvrNB20+3NmnhsGPv4zhy+DaKeYkT8iApMsbyl7i8W1Eoon4HZ+C0 UPcJmkA0+wIqJgrRh1z20YvDvY8vlpwKc6bYR6kbdYBpA0bwfI1JvhBsK3Fr2E22WfWH vM0kbjPbUVf1j0sOnRoczxZcKEUvHpe5IHa0AoXmmSKKyW0yCTtWgoXbdzxsVbLAFXcE uw== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Cc: "Dominik 'Disconnect3d' Czarnota" , Christian Borntraeger , Andreas Arnez , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH RESEND 2/6] gdbstub: Expose gdb_get_process() and gdb_get_first_cpu_in_process() Date: Wed, 10 May 2023 22:26:50 +0200 Message-Id: <20230510202654.225689-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510202654.225689-1-iii@linux.ibm.com> References: <20230510202654.225689-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: D_A6662MQ3yV5_4ctABh4qMgZhu3DBMY X-Proofpoint-GUID: 7ArZCWDVUCYi_N5hvRkNXvZUzHcyGex3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100163 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=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1683750512451100004 Content-Type: text/plain; charset="utf-8" These functions will be needed by user-target.c in order to retrieve the name of the executable. Signed-off-by: Ilya Leoshkevich Reviewed-by: Alex Benn=C3=A9e --- gdbstub/gdbstub.c | 16 ++++++++-------- gdbstub/internals.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 0760d786858..207250c1c08 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -211,7 +211,7 @@ static uint32_t gdb_get_cpu_pid(CPUState *cpu) return cpu->cluster_index + 1; } =20 -static GDBProcess *gdb_get_process(uint32_t pid) +GDBProcess *gdb_get_process(uint32_t pid) { int i; =20 @@ -247,7 +247,7 @@ static CPUState *find_cpu(uint32_t thread_id) return NULL; } =20 -static CPUState *get_first_cpu_in_process(GDBProcess *process) +CPUState *gdb_get_first_cpu_in_process(GDBProcess *process) { CPUState *cpu; =20 @@ -325,7 +325,7 @@ static CPUState *gdb_get_cpu(uint32_t pid, uint32_t tid) return NULL; } =20 - return get_first_cpu_in_process(process); + return gdb_get_first_cpu_in_process(process); } else { /* a specific thread */ cpu =3D find_cpu(tid); @@ -354,7 +354,7 @@ static const char *get_feature_xml(const char *p, const= char **newp, size_t len; int i; const char *name; - CPUState *cpu =3D get_first_cpu_in_process(process); + CPUState *cpu =3D gdb_get_first_cpu_in_process(process); CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 len =3D 0; @@ -490,7 +490,7 @@ void gdb_register_coprocessor(CPUState *cpu, =20 static void gdb_process_breakpoint_remove_all(GDBProcess *p) { - CPUState *cpu =3D get_first_cpu_in_process(p); + CPUState *cpu =3D gdb_get_first_cpu_in_process(p); =20 while (cpu) { gdb_breakpoint_remove_all(cpu); @@ -653,7 +653,7 @@ static int gdb_handle_vcont(const char *p) goto out; } =20 - cpu =3D get_first_cpu_in_process(process); + cpu =3D gdb_get_first_cpu_in_process(process); while (cpu) { if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; @@ -1274,7 +1274,7 @@ static void handle_v_attach(GArray *params, void *use= r_ctx) goto cleanup; } =20 - cpu =3D get_first_cpu_in_process(process); + cpu =3D gdb_get_first_cpu_in_process(process); if (!cpu) { goto cleanup; } @@ -1392,7 +1392,7 @@ static void handle_query_curr_tid(GArray *params, voi= d *user_ctx) * first thread). */ process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); - cpu =3D get_first_cpu_in_process(process); + cpu =3D gdb_get_first_cpu_in_process(process); g_string_assign(gdbserver_state.str_buf, "QC"); gdb_append_thread_id(cpu, gdbserver_state.str_buf); gdb_put_strbuf(); diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 94ddff44958..235f2551bd4 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -124,6 +124,8 @@ void gdb_read_byte(uint8_t ch); */ bool gdb_got_immediate_ack(void); /* utility helpers */ +GDBProcess *gdb_get_process(uint32_t pid); +CPUState *gdb_get_first_cpu_in_process(GDBProcess *process); CPUState *gdb_first_attached_cpu(void); void gdb_append_thread_id(CPUState *cpu, GString *buf); int gdb_get_cpu_index(CPUState *cpu); --=20 2.40.1 From nobody Mon May 20 17:29:56 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1683750485; cv=none; d=zohomail.com; s=zohoarc; b=gULgjyqHJ34ZRWtLTjIwL7LLm4g068N5yz81Ij07Qy+/t0XFJvv/LtQhKJtiu8Pabkdqikal+VYcr6e+7lZxUs1wZQ6/nekVG/BcSnh8rkpjXpZsxcLY6wqDgrRWiLWijWfskMXdH6+zIaBvYxuETQdqpulG48dyCuZ+cFsmlkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683750485; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y+Bi/737AeovmPj6RecQOoOrpJYl9LcQZi/nPXrlhoQ=; b=KgLYIpVZfKURhd4xcV8aY5fzXuQaAiobzctdzM6bAX/reNMxbs6O/uClsvWs7DxhtNO+MfV5wTHJctvurM/97/toYWMf6zHiJtDfVpSTeVBFIcRVBAq1U4F+PsTiiXBmf4PUvh4CHG4Bm3gt4LppmKNjaWNlfoq+Ne1u/Ycvkao= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16837504855101006.0481233848349; Wed, 10 May 2023 13:28:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqPF-0000IU-BW; Wed, 10 May 2023 16:27:25 -0400 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 1pwqP7-0000HH-I9 for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqP5-0000zp-QV for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:17 -0400 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AK9LjB017369; Wed, 10 May 2023 20:27:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduud0v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:12 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34AK9iAk020102; Wed, 10 May 2023 20:27:11 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduucyn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:11 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34A3KOvN018561; Wed, 10 May 2023 20:27:09 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3qf7nh197h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:09 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34AKR62K5046894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 May 2023 20:27:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D13A20043; Wed, 10 May 2023 20:27:06 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CAD592004B; Wed, 10 May 2023 20:27:05 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.51.237]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 May 2023 20:27:05 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=y+Bi/737AeovmPj6RecQOoOrpJYl9LcQZi/nPXrlhoQ=; b=kYElFhYw3Lx3K2YAVBUcKajsyobZfCEohdOvG2qv9B8yJxa1nieoRQU3IML/LQlIx0qt qTAYsXNrEA2aTFVJ/mZ+EzB1amqv8wgD7/EDNID8iWEMwrJ5M79Zz6pJLBNqIO/l5t+5 b/PpfixQRyd/WeOUmsMf12/9BfivGkzZ66HIuyB3Y7TC/sXNU7pdayDZM+Yx+WccZxU4 1KYnPiA8RfUW8JYfS/MIMGJ41nQa9OxSINGe9gnY18J/xCtQo9LWEzMh6wJ3hZaRTHLm spFCYAq4FlwNXTr/KfUm/3Zs7mPX1L1mbZUj/7/VElDvPoZMpzFJZGpEM2SNvVLaCw34 6Q== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Cc: "Dominik 'Disconnect3d' Czarnota" , Christian Borntraeger , Andreas Arnez , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH RESEND 3/6] gdbstub: Report the actual qemu-user pid Date: Wed, 10 May 2023 22:26:51 +0200 Message-Id: <20230510202654.225689-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510202654.225689-1-iii@linux.ibm.com> References: <20230510202654.225689-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: StL46C74yRZT1kzUG6AdCAr67mq-gjcp X-Proofpoint-GUID: iVS1M6BWKCLlbMqBiFVrBMAxKBO-NhX0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100163 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=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1683750486967100005 Content-Type: text/plain; charset="utf-8" Currently qemu-user reports pid 1 to GDB. Resolve the TODO and report the actual PID. Using getpid() relies on the assumption that there is only one GDBProcess. Add an assertion to make sure that future changes don't break it. Signed-off-by: Ilya Leoshkevich Reviewed-by: Alex Benn=C3=A9e --- gdbstub/gdbstub.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 207250c1c08..003db59b1b2 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -202,13 +202,16 @@ void gdb_memtox(GString *buf, const char *mem, int le= n) =20 static uint32_t gdb_get_cpu_pid(CPUState *cpu) { - /* TODO: In user mode, we should use the task state PID */ +#ifdef CONFIG_USER_ONLY + return getpid(); +#else if (cpu->cluster_index =3D=3D UNASSIGNED_CLUSTER_INDEX) { /* Return the default process' PID */ int index =3D gdbserver_state.process_num - 1; return gdbserver_state.processes[index].pid; } return cpu->cluster_index + 1; +#endif } =20 GDBProcess *gdb_get_process(uint32_t pid) @@ -2127,19 +2130,25 @@ void gdb_read_byte(uint8_t ch) void gdb_create_default_process(GDBState *s) { GDBProcess *process; - int max_pid =3D 0; + int pid; =20 +#ifdef CONFIG_USER_ONLY + assert(gdbserver_state.process_num =3D=3D 0); + pid =3D getpid(); +#else if (gdbserver_state.process_num) { - max_pid =3D s->processes[s->process_num - 1].pid; + pid =3D s->processes[s->process_num - 1].pid; + } else { + pid =3D 0; } + /* We need an available PID slot for this process */ + assert(pid < UINT32_MAX); + pid++; +#endif =20 s->processes =3D g_renew(GDBProcess, s->processes, ++s->process_num); process =3D &s->processes[s->process_num - 1]; - - /* We need an available PID slot for this process */ - assert(max_pid < UINT32_MAX); - - process->pid =3D max_pid + 1; + process->pid =3D pid; process->attached =3D false; process->target_xml[0] =3D '\0'; } --=20 2.40.1 From nobody Mon May 20 17:29:56 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1683750498; cv=none; d=zohomail.com; s=zohoarc; b=LaVX7PPrT/xrO+mYMeQFAEnHn1s7g7CbXsAFB6z9yFfOSo2bweCOR962MNmXwP0oOpDIo6w6J7WVm0L43YI2inw37goAbE74kGUrdnKJQQo3ohVNQZkTo4adCyK7+GPo7DVyAbBjEfnFIi3gJJ7lS/gdnfuUegqNJMC8YsK1eqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683750498; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GfYhGRgHsUOkWYOfNOk7ldZHpOFTKcvwznE9KwgdpeU=; b=iomC2lsFr0cq7WQdJgfdwsLlxJAiVkM9+M9xvWCUc8FVhBFJAH1e0qjZHzjboCVodYrPqXgSWYPHMbPsTH7IOI2SuhXafOw4tL6LuKtpCTfjaOcC0Bbwi/YfsHQ69FkNRjAvKv06pG4VMnHWj4UhtjqZZAiCyT+1wz6Gyuho3zU= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683750498358693.637477139383; Wed, 10 May 2023 13:28:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqPR-0000Mg-CN; Wed, 10 May 2023 16:27:37 -0400 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 1pwqPA-0000IA-07 for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqP7-00010N-Nn for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:19 -0400 Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AK8eZu015242; Wed, 10 May 2023 20:27:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgbxmcxjq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:15 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34AKNan3004512; Wed, 10 May 2023 20:27:14 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgbxmcxhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:14 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34AJ0GOO012774; Wed, 10 May 2023 20:27:11 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3qf7nh197j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:10 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34AKR7Bl8979128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 May 2023 20:27:07 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 65A592004E; Wed, 10 May 2023 20:27:07 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D4CC020063; Wed, 10 May 2023 20:27:06 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.51.237]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 May 2023 20:27:06 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=GfYhGRgHsUOkWYOfNOk7ldZHpOFTKcvwznE9KwgdpeU=; b=jAAoajTA3ZToLLOL1dbptKs7nUF/HyrzH0oSkfzV9YsT5sxtRboYk4B/ScKEdsJadBCJ RUR0JZuDkwMUrXSK4mriOYDExOSYhhmuhYfYDTm5O7iPxaWjCuwxJ30KPiEqf8Wi0ElW Nnf1uNIJ/Mu2vZSn/WXNj00UD18OFrMQ4iLfXarh3rTpdGHY9qS82Hjru1QA5VnBLATk Dl4nPPk5Zmk1a+T7pMKpx6LwcYjovJHwv8F9KLvigtfWUslxesbCaAw1GqH/m2Yo4Mnx 97Nbw+QO553N3db3+YpqbUseECJ6uwyUz6qicP01TiNexXSUuzJBZ7La+NLoS81cH/8A 8Q== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Cc: "Dominik 'Disconnect3d' Czarnota" , Christian Borntraeger , Andreas Arnez , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH RESEND 4/6] gdbstub: Add support for info proc mappings Date: Wed, 10 May 2023 22:26:52 +0200 Message-Id: <20230510202654.225689-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510202654.225689-1-iii@linux.ibm.com> References: <20230510202654.225689-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 2nYY3gIvJ6T5aRW5_8hoySzXqqsCZlNO X-Proofpoint-GUID: dBIGikKBqw1c3IxKBRrDiaYCMF6iLEtM Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 suspectscore=0 bulkscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100163 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=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1683750500441100001 Content-Type: text/plain; charset="utf-8" Currently the GDB's generate-core-file command doesn't work well with qemu-user: the resulting dumps are huge [1] and at the same time incomplete (argv and envp are missing). The reason is that GDB has no access to proc mappings and therefore has to fall back to using heuristics for discovering them. This is, in turn, because qemu-user does not implement the Host I/O feature of the GDB Remote Serial Protocol. Implement vFile:{open,close,pread,readlink} and also qXfer:exec-file:read+. With that, generate-core-file begins to work on aarch64 and s390x, albeit with two deficiencies: * GDB still tries to dump the host mappings, because QEMU does not fake /proc/$PID/smaps (as opposed to /proc/$PID/maps). The user-visible effect is only a bunch of warnings. * PT_LOAD segments lack PF_X flags (I have not debugged this). The impact of these issues on usability is fairly low, so they can be resolved later. [1] https://sourceware.org/pipermail/gdb-patches/2023-May/199432.html Co-developed-by: Dominik 'Disconnect3d' Czarnota Signed-off-by: Ilya Leoshkevich --- gdbstub/gdbstub.c | 45 +++++++++++++- gdbstub/internals.h | 5 ++ gdbstub/user-target.c | 139 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 2 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 003db59b1b2..c4112d6eacd 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1326,6 +1326,36 @@ static const GdbCmdParseEntry gdb_v_commands_table[]= =3D { .cmd =3D "Kill;", .cmd_startswith =3D 1 }, +#ifdef CONFIG_USER_ONLY + /* + * Host I/O Packets. See [1] for details. + * [1] https://sourceware.org/gdb/onlinedocs/gdb/Host-I_002fO-Packets.= html + */ + { + .handler =3D gdb_handle_v_file_open, + .cmd =3D "File:open:", + .cmd_startswith =3D 1, + .schema =3D "s,L,L0" + }, + { + .handler =3D gdb_handle_v_file_close, + .cmd =3D "File:close:", + .cmd_startswith =3D 1, + .schema =3D "l0" + }, + { + .handler =3D gdb_handle_v_file_pread, + .cmd =3D "File:pread:", + .cmd_startswith =3D 1, + .schema =3D "l,L,L0" + }, + { + .handler =3D gdb_handle_v_file_readlink, + .cmd =3D "File:readlink:", + .cmd_startswith =3D 1, + .schema =3D "s0" + }, +#endif }; =20 static void handle_v_commands(GArray *params, void *user_ctx) @@ -1471,11 +1501,14 @@ static void handle_query_supported(GArray *params, = void *user_ctx) ";ReverseStep+;ReverseContinue+"); } =20 -#if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX) +#if defined(CONFIG_USER_ONLY) +#if defined(CONFIG_LINUX) if (gdbserver_state.c_cpu->opaque) { g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+"); } #endif + g_string_append(gdbserver_state.str_buf, ";qXfer:exec-file:read+"); +#endif =20 if (params->len && strstr(get_param(params, 0)->data, "multiprocess+")) { @@ -1614,13 +1647,21 @@ static const GdbCmdParseEntry gdb_gen_query_table[]= =3D { .cmd_startswith =3D 1, .schema =3D "s:l,l0" }, -#if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX) +#if defined(CONFIG_USER_ONLY) +#if defined(CONFIG_LINUX) { .handler =3D gdb_handle_query_xfer_auxv, .cmd =3D "Xfer:auxv:read::", .cmd_startswith =3D 1, .schema =3D "l,l0" }, +#endif + { + .handler =3D gdb_handle_query_xfer_exec_file, + .cmd =3D "Xfer:exec-file:read:", + .cmd_startswith =3D 1, + .schema =3D "l:l,l0" + }, #endif { .handler =3D gdb_handle_query_attached, diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 235f2551bd4..c1217337812 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -184,6 +184,11 @@ typedef union GdbCmdVariant { void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */ void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ +void gdb_handle_v_file_open(GArray *params, void *user_ctx); /* user */ +void gdb_handle_v_file_close(GArray *params, void *user_ctx); /* user */ +void gdb_handle_v_file_pread(GArray *params, void *user_ctx); /* user */ +void gdb_handle_v_file_readlink(GArray *params, void *user_ctx); /* user */ +void gdb_handle_query_xfer_exec_file(GArray *params, void *user_ctx); /* u= ser */ =20 void gdb_handle_query_attached(GArray *params, void *user_ctx); /* both */ =20 diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c index fa0e59ec9a5..09df05b5526 100644 --- a/gdbstub/user-target.c +++ b/gdbstub/user-target.c @@ -11,6 +11,10 @@ #include "exec/gdbstub.h" #include "qemu.h" #include "internals.h" +#ifdef CONFIG_LINUX +#include "linux-user/loader.h" +#include "linux-user/qemu.h" +#endif =20 /* * Map target signal numbers to GDB protocol signal numbers and vice @@ -281,3 +285,138 @@ void gdb_handle_query_xfer_auxv(GArray *params, void = *user_ctx) gdbserver_state.str_buf->len, true); } #endif + +static const char *get_filename_param(GArray *params, int i) +{ + const char *hex_filename =3D get_param(params, i)->data; + gdb_hextomem(gdbserver_state.mem_buf, hex_filename, + strlen(hex_filename) / 2); + g_byte_array_append(gdbserver_state.mem_buf, (const guint8 *)"", 1); + return (const char *)gdbserver_state.mem_buf->data; +} + +static void hostio_reply_with_data(const void *buf, size_t n) +{ + g_string_printf(gdbserver_state.str_buf, "F%lx;", n); + gdb_memtox(gdbserver_state.str_buf, buf, n); + gdb_put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); +} + +void gdb_handle_v_file_open(GArray *params, void *user_ctx) +{ + const char *filename =3D get_filename_param(params, 0); + uint64_t flags =3D get_param(params, 1)->val_ull; + uint64_t mode =3D get_param(params, 2)->val_ull; + +#ifdef CONFIG_LINUX + int fd =3D do_guest_openat(gdbserver_state.g_cpu->env_ptr, 0, filename, + flags, mode); +#else + int fd =3D open(filename, flags, mode); +#endif + if (fd < 0) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + } else { + g_string_printf(gdbserver_state.str_buf, "F%d", fd); + } + gdb_put_strbuf(); +} + +void gdb_handle_v_file_close(GArray *params, void *user_ctx) +{ + int fd =3D get_param(params, 0)->val_ul; + + if (close(fd) =3D=3D -1) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + gdb_put_strbuf(); + return; + } + + gdb_put_packet("F00"); +} + +#define BUFSIZ 8192 + +void gdb_handle_v_file_pread(GArray *params, void *user_ctx) +{ + int fd =3D get_param(params, 0)->val_ul; + size_t count =3D get_param(params, 1)->val_ull; + off_t offset =3D get_param(params, 2)->val_ull; + + size_t bufsiz =3D MIN(count, BUFSIZ); + g_autofree char *buf =3D g_try_malloc(bufsiz); + if (buf =3D=3D NULL) { + gdb_put_packet("E12"); + return; + } + + ssize_t n =3D pread(fd, buf, bufsiz, offset); + if (n < 0) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + gdb_put_strbuf(); + return; + } + hostio_reply_with_data(buf, n); +} + +void gdb_handle_v_file_readlink(GArray *params, void *user_ctx) +{ + const char *filename =3D get_filename_param(params, 0); + + g_autofree char *buf =3D g_try_malloc(BUFSIZ); + if (buf =3D=3D NULL) { + gdb_put_packet("E12"); + return; + } + +#ifdef CONFIG_LINUX + ssize_t n =3D do_guest_readlink(filename, buf, BUFSIZ); +#else + ssize_t n =3D readlink(filename, buf, BUFSIZ); +#endif + if (n < 0) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + gdb_put_strbuf(); + return; + } + hostio_reply_with_data(buf, n); +} + +void gdb_handle_query_xfer_exec_file(GArray *params, void *user_ctx) +{ + uint32_t pid =3D get_param(params, 0)->val_ul; + uint32_t offset =3D get_param(params, 1)->val_ul; + uint32_t length =3D get_param(params, 2)->val_ul; + + GDBProcess *process =3D gdb_get_process(pid); + if (!process) { + gdb_put_packet("E00"); + return; + } + + CPUState *cpu =3D gdb_get_first_cpu_in_process(process); + if (!cpu) { + gdb_put_packet("E00"); + return; + } + + TaskState *ts =3D cpu->opaque; + if (!ts || !ts->bprm || !ts->bprm->filename) { + gdb_put_packet("E00"); + return; + } + + size_t total_length =3D strlen(ts->bprm->filename); + if (offset > total_length) { + gdb_put_packet("E00"); + return; + } + if (offset + length > total_length) { + length =3D total_length - offset; + } + + g_string_printf(gdbserver_state.str_buf, "l%.*s", length, + ts->bprm->filename + offset); + gdb_put_strbuf(); +} --=20 2.40.1 From nobody Mon May 20 17:29:56 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1683750526; cv=none; d=zohomail.com; s=zohoarc; b=DDTpdc1RdPgAK27rsGUHAhLQwJgaoqIL9HBZxLu9MrAIlM2aMMZOYeBQHZXuxLOVp+pYxvQv8EkbnQ4P5IXri/yxlF4rPwza5bYTnXyazS2G1NL1VGZ3ygHNWMQ2UrGxziMs/TPajxOnfy5M0s6fy+ZMFnmkKJ6NsA2fZ3WXqXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683750526; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E/oqGWqW+Yxx3TSzYwum9cBpxEeD6uL2WVg7QRCZIoc=; b=HYcGXUU+4UQY12HCCATTJ4lvKxLqnB6u3/ZgnRZlNBKAzQfsSLaLgIh0xZrSMNoAUhcTzQG2XOT4LAWo9YbH3m5oqmoL99vcJfTPxMlCv6GSC0Y3bUSU24LA0cVoClFLTt9PNadudmff6d/6AQn9tzVVM79eefgLXAGJ+5rTfgo= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683750526414833.108252068733; Wed, 10 May 2023 13:28:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqPD-0000IR-Ms; Wed, 10 May 2023 16:27:23 -0400 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 1pwqP8-0000Hf-QZ for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:18 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqP5-000102-Rl for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:18 -0400 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AKJnol024633; Wed, 10 May 2023 20:27:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduud1u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:14 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34AKLQgR028454; Wed, 10 May 2023 20:27:13 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduud13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:13 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34AJA1aJ005404; Wed, 10 May 2023 20:27:12 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0s17p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:11 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34AKR8KF21430854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 May 2023 20:27:08 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7C0272006A; Wed, 10 May 2023 20:27:08 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E89642004E; Wed, 10 May 2023 20:27:07 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.51.237]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 May 2023 20:27:07 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=E/oqGWqW+Yxx3TSzYwum9cBpxEeD6uL2WVg7QRCZIoc=; b=Q9QERfRTZyux7JYBkARMz/PFrKx4aQJruANq4JW6970381xCjFx9PIaLDekrD6yZPbY3 sRyc1OET8xuK0f6pGsaGXwGkW4SrhAcFgLu1rzqYAi1qCkJBbtTp2RDl8J2qkFGqPV/P xMDjNZYQvxlxgyejlj1wnFL4khMcyXOJmHnmUmoTHc0XX2UiYHyG9nRicEbSpT6MHdRk xW4uXJv5NGhyoBHt/eLPXfo8OcYJEiXQfbyKfAj4lqC15XRVvXKpRiNlFaG7ra8jxaKj F8gnxUXFzoUy5tVq7zu40U9xunS5FATlftwgroMGgcMMmZwMWVwYBMyBOGLANQb89EDT ww== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Cc: "Dominik 'Disconnect3d' Czarnota" , Christian Borntraeger , Andreas Arnez , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH RESEND 5/6] docs: Document security implications of debugging Date: Wed, 10 May 2023 22:26:53 +0200 Message-Id: <20230510202654.225689-6-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510202654.225689-1-iii@linux.ibm.com> References: <20230510202654.225689-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lc_lsZZC8hwcXsZxOIurlOz2HzBfDjVa X-Proofpoint-GUID: AAs7r7BcH4IlTmt_FQ8ESI8U582Tdlrm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100163 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=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1683750526927100001 Content-Type: text/plain; charset="utf-8" Now that the GDB stub implements reading host files, concerns may arise that it undermines security. Document the status quo, which is that the users are already responsible for securing the GDB connection themselves. Signed-off-by: Ilya Leoshkevich Reviewed-by: Alex Benn=C3=A9e --- docs/system/gdb.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/system/gdb.rst b/docs/system/gdb.rst index 453eb73f6c4..3cc5167d928 100644 --- a/docs/system/gdb.rst +++ b/docs/system/gdb.rst @@ -192,3 +192,18 @@ The memory mode can be checked by sending the followin= g command: =20 ``maintenance packet Qqemu.PhyMemMode:0`` This will change it back to normal memory mode. + +Security considerations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Connecting to the GDB socket allows running arbitrary code inside the gues= t; +in case of the TCG emulation, which is not considered a security boundary,= this +also means running arbitrary code on the host. Additionally, when debugging +qemu-user, it allows directly downloading any file readable by QEMU from t= he +host. + +The GDB socket is not protected by authentication, authorization or encryp= tion. +It is therefore a responsibility of the user to make sure that only author= ized +clients can connect to it, e.g., by using a unix socket with proper +permissions, or by opening a TCP socket only on interfaces that are not +reachable by potential attackers. --=20 2.40.1 From nobody Mon May 20 17:29:56 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1683750493; cv=none; d=zohomail.com; s=zohoarc; b=QCiXhwDreFB1/UlySbWIefWUdzBfdWlSjQ2AacGeeGJF5yrNYlb16tWFiH0uAsm2aO5Vln79W8ZtQYC0fRb//OroUtB3gfSTx0+KfM5QllaudPy9pK1YsJACx94dyZgUY31NM5iAEH/D7CuXe9Q8kdQDnEsQ/VLIocIuBAk3Das= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683750493; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aivPc29fYOKkw5TRsdyySn7KdXwca0cBNGqfVT6wZ7o=; b=Zt9YjfE2vmGp1N1OXhLCBiQbvtDKcdaiaDMvUlCkSZujzQlVpUOzyV+iGYQzKHLkz+qMJiRbLeRK39UQSCxfgfS9Yj0nE8x540Oj5/BgcooJu4EKaOgR9dzrHcpB8Byd/+SCW1tG+5z+AnzAZLjuxeONt7FSs+Ach6v7JuGIO18= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683750493610725.0531058334625; Wed, 10 May 2023 13:28:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqPQ-0000M2-Nu; Wed, 10 May 2023 16:27:36 -0400 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 1pwqPA-0000IJ-Jf for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:20 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqP7-00010X-Vd for qemu-devel@nongnu.org; Wed, 10 May 2023 16:27:20 -0400 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AK9L62017364; Wed, 10 May 2023 20:27:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduud2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:16 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34AK9Z6v018523; Wed, 10 May 2023 20:27:16 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qgcduud1t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:16 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34AGbu9S021072; Wed, 10 May 2023 20:27:13 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3qf84e995q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 20:27:13 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34AKRA9R30933446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 May 2023 20:27:10 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E594D2004D; Wed, 10 May 2023 20:27:09 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60D2220040; Wed, 10 May 2023 20:27:09 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.51.237]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 May 2023 20:27:09 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=aivPc29fYOKkw5TRsdyySn7KdXwca0cBNGqfVT6wZ7o=; b=QI3UU4SdIIHm8+G+BPmNX9Wm2QVqahCsPo8PoN1vtZb5uUYXrzmWB76hQpAOjhVIYJqg FALDvcCOLMd9HetZuC7KVus1EwHUOj2NUbDstC41dXwYK4ko0qjMxI2HniDeJirCW6D4 SLCjT/JvPX6zRBkPzFsCqHtMlSratl+fi93TnAZVF2xi+iJ31Oz7klaEHMGa2KPeJL13 YRnlNN0kjSn5fCoadvKH/jWicEsjg0kEyc53tYbHPdswl4ibeJMEJO1CtIXzFLqwFLQW gHdeIeLSMWVfvw6rEH5lA75xsOZORZzuOZFB9PNNhxj0Vd8eZdbp4VaVWiNCzoVLvf7n WQ== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Cc: "Dominik 'Disconnect3d' Czarnota" , Christian Borntraeger , Andreas Arnez , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH RESEND 6/6] tests/tcg: Add a test for info proc mappings Date: Wed, 10 May 2023 22:26:54 +0200 Message-Id: <20230510202654.225689-7-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230510202654.225689-1-iii@linux.ibm.com> References: <20230510202654.225689-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vyNUWac2l4O0ON2Z5a22jwO6DhhorA34 X-Proofpoint-GUID: ThkaK9y7ORONub4qp9NuLudKc0OGGefA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=971 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100163 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=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1683750494804100001 Content-Type: text/plain; charset="utf-8" Add a small test to prevent regressions. Since there are issues with how GDB interprets QEMU's target.xml, enable the test only on aarch64 and s390x for now. Signed-off-by: Ilya Leoshkevich --- tests/tcg/aarch64/Makefile.target | 3 +- tests/tcg/multiarch/Makefile.target | 7 +++ .../multiarch/gdbstub/test-proc-mappings.py | 55 +++++++++++++++++++ tests/tcg/s390x/Makefile.target | 2 +- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/multiarch/gdbstub/test-proc-mappings.py diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 03157954871..38402b0ba1f 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -97,7 +97,8 @@ run-gdbstub-sve-ioctls: sve-ioctls --bin $< --test $(AARCH64_SRC)/gdbstub/test-sve-ioctl.py, \ basic gdbstub SVE ZLEN support) =20 -EXTRA_RUNS +=3D run-gdbstub-sysregs run-gdbstub-sve-ioctls +EXTRA_RUNS +=3D run-gdbstub-sysregs run-gdbstub-sve-ioctls \ + run-gdbstub-proc-mappings endif endif =20 diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index 373db696481..cbc0b75787a 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -81,6 +81,13 @@ run-gdbstub-qxfer-auxv-read: sha1 --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-auxv-read.py, \ basic gdbstub qXfer:auxv:read support) =20 +run-gdbstub-proc-mappings: sha1 + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-proc-mappings.py, \ + proc mappings support) + run-gdbstub-thread-breakpoint: testthread $(call run-test, $@, $(GDB_SCRIPT) \ --gdb $(HAVE_GDB_BIN) \ diff --git a/tests/tcg/multiarch/gdbstub/test-proc-mappings.py b/tests/tcg/= multiarch/gdbstub/test-proc-mappings.py new file mode 100644 index 00000000000..657e36a2fc7 --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/test-proc-mappings.py @@ -0,0 +1,55 @@ +"""Test that gdbstub has access to proc mappings. + +This runs as a sourced script (via -x, via run-test.py).""" +from __future__ import print_function +import gdb +import sys + + +n_failures =3D 0 + + +def report(cond, msg): + """Report success/fail of a test""" + if cond: + print("PASS: {}".format(msg)) + else: + print("FAIL: {}".format(msg)) + global n_failures + n_failures +=3D 1 + + +def run_test(): + """Run through the tests one by one""" + mappings =3D gdb.execute("info proc mappings", False, True) + report(isinstance(mappings, str), "Fetched the mappings from the infer= ior") + report("/sha1" in mappings, "Found the test binary name in the mapping= s") + + +def main(): + """Prepare the environment and run through the tests""" + try: + inferior =3D gdb.selected_inferior() + print("ATTACHED: {}".format(inferior.architecture().name())) + except (gdb.error, AttributeError): + print("SKIPPING (not connected)") + exit(0) + + if gdb.parse_and_eval('$pc') =3D=3D 0: + print("SKIP: PC not set") + exit(0) + + try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() + except gdb.error: + report(False, "GDB Exception: {}".format(sys.exc_info()[0])) + print("All tests complete: %d failures" % n_failures) + exit(n_failures) + + +main() diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.tar= get index 0031868b136..2934ac9adf2 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -74,7 +74,7 @@ run-gdbstub-signals-s390x: signals-s390x --bin $< --test $(S390X_SRC)/gdbstub/test-signals-s390x.py, \ mixing signals and debugging) =20 -EXTRA_RUNS +=3D run-gdbstub-signals-s390x +EXTRA_RUNS +=3D run-gdbstub-signals-s390x run-gdbstub-proc-mappings endif =20 # MVX versions of sha512 --=20 2.40.1