From nobody Wed Feb 5 15:59:12 2025 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=1737073082; cv=none; d=zohomail.com; s=zohoarc; b=VgGjIzzWmQHRKC4OepgC4fLCP4UFuTuUIgg4yTlOmadyvlDThjbpf/kTiHKhS2g+FKSKCeWYwmUjctXyZ1Bg1wINlgvLR7lIssw7DU8JAS9SqVLx1+u03+7rPq5AM/d2CcVlQaeLqe5qffv7dgTUdWsn0Qx9qCtj/JXKKbQGcL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737073082; 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=4fu3GDQOQ9FOS9iFSYy+3L5RzBVEUo1P+XpIXrxmcI4=; b=C1zT2953fhiShmpDmxFRsgptuupZB9nz06ADTycTktd7edvHKgYRT9FCty8zctXKFyAOfJG2CM7KADrSy5LCXcmWyBZuPlKVXG9YLCCvPumFieL7fVXExXYgMxJxWgnNA5X2arQImGW6sRyg3CMuy3mvCy+mbcizaOPgJRCmacY= 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 1737073082377192.69218857640055; Thu, 16 Jan 2025 16:18:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYa1t-00029U-Ol; Thu, 16 Jan 2025 19:16:05 -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 1tYa1q-00028D-RB for qemu-devel@nongnu.org; Thu, 16 Jan 2025 19:16:02 -0500 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 1tYa1n-0008KE-CE for qemu-devel@nongnu.org; Thu, 16 Jan 2025 19:16:02 -0500 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50GM0VKn007885; Fri, 17 Jan 2025 00:15:49 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 446tkcnefy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jan 2025 00:15:49 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50GKSMhW004540; Fri, 17 Jan 2025 00:15:48 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4442yt0jk2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jan 2025 00:15:48 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50H0FkK940042938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jan 2025 00:15:46 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB17C2004B; Fri, 17 Jan 2025 00:15:46 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 49DEA20040; Fri, 17 Jan 2025 00:15:46 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.171.62.46]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 17 Jan 2025 00:15:46 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=4fu3GDQOQ9FOS9iFS Yy+3L5RzBVEUo1P+XpIXrxmcI4=; b=hfuUJGmS9yRnv60GNAH5xgbUwzQsQNT/e 5hjsZVvInwm/rrAQzpwA3hizAz4g1/NsnNukjPLY+zyZ7XWq+Uvs6PK8GwYRIcsc Hq9dGHaAMQt/iKk/IPZjTxhgJ/ISCqle53+kKkCOGSANOI9VXc/1zBzRbjUSQw8e sX627N/dCFvzbmzNaKqxNwjHmzb5Ql5cYz9ekCkg4Zrla0vusvFBOQ7x2LCfn4gY ORBVotMFk62u8yPSCp6s9TGgVtkXLupm+odLqcsTjIYeP7SdNKj+upvPCer2TZ41 8niRsCvVFMitui2hmrqR2lcoZkkPYkMejIlD+ns76BDnoVIftH3BA== From: Ilya Leoshkevich To: Warner Losh , Riku Voipio , Laurent Vivier , Paolo Bonzini , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Cc: Kyle Evans , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Ilya Leoshkevich Subject: [PATCH v6 2/8] gdbstub: Try unlinking the unix socket before binding Date: Fri, 17 Jan 2025 01:11:27 +0100 Message-ID: <20250117001542.8290-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250117001542.8290-1-iii@linux.ibm.com> References: <20250117001542.8290-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lBpMcVpkEUIGWomKJemK5xmVh_c4Nb3M X-Proofpoint-GUID: lBpMcVpkEUIGWomKJemK5xmVh_c4Nb3M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-16_10,2025-01-16_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 impostorscore=0 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 suspectscore=0 clxscore=1015 mlxlogscore=923 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501160178 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: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1.797, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1737073084494019000 Content-Type: text/plain; charset="utf-8" In case an emulated process execve()s another emulated process, bind() will fail, because the socket already exists. So try deleting it. Use the existing unix_listen() function which does this. Link qemu-user with qemu-sockets.c and add the monitor_get_fd() stub. Note that it is not possible to handle this in do_execv(): deleting gdbserver_user_state.socket_path before safe_execve() is not correct, because the latter may fail, and afterwards we may lose control. Signed-off-by: Ilya Leoshkevich Reviewed-by: Alex Benn=C3=A9e --- gdbstub/user.c | 29 +++-------------------------- stubs/meson.build | 2 ++ stubs/monitor-fd.c | 9 +++++++++ util/meson.build | 2 ++ 4 files changed, 16 insertions(+), 26 deletions(-) create mode 100644 stubs/monitor-fd.c diff --git a/gdbstub/user.c b/gdbstub/user.c index fd29d595f40..8225b702802 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -315,12 +315,10 @@ static bool gdb_accept_socket(int gdb_fd) return true; } =20 -static int gdbserver_open_socket(const char *path) +static int gdbserver_open_socket(const char *path, Error **errp) { g_autoptr(GString) buf =3D g_string_new(""); - struct sockaddr_un sockaddr =3D {}; char *pid_placeholder; - int fd, ret; =20 pid_placeholder =3D strstr(path, "%d"); if (pid_placeholder !=3D NULL) { @@ -330,28 +328,7 @@ static int gdbserver_open_socket(const char *path) path =3D buf->str; } =20 - fd =3D socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) { - perror("create socket"); - return -1; - } - - sockaddr.sun_family =3D AF_UNIX; - pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path); - ret =3D bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); - if (ret < 0) { - perror("bind socket"); - close(fd); - return -1; - } - ret =3D listen(fd, 1); - if (ret < 0) { - perror("listen socket"); - close(fd); - return -1; - } - - return fd; + return unix_listen(path, errp); } =20 static bool gdb_accept_tcp(int gdb_fd) @@ -424,7 +401,7 @@ bool gdbserver_start(const char *port_or_path, Error **= errp) if (port > 0) { gdb_fd =3D gdbserver_open_port(port, errp); } else { - gdb_fd =3D gdbserver_open_socket(port_or_path); + gdb_fd =3D gdbserver_open_socket(port_or_path, errp); } =20 if (gdb_fd < 0) { diff --git a/stubs/meson.build b/stubs/meson.build index e91614a874d..17168d03eed 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -61,6 +61,8 @@ if have_user if not (have_system or have_tools) stub_ss.add(files('qdev.c')) endif + + stub_ss.add(files('monitor-fd.c')) endif =20 if have_system diff --git a/stubs/monitor-fd.c b/stubs/monitor-fd.c new file mode 100644 index 00000000000..9bb67498850 --- /dev/null +++ b/stubs/monitor-fd.c @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "monitor/monitor.h" + +int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) +{ + abort(); +} diff --git a/util/meson.build b/util/meson.build index 5d8bef98912..780b5977a89 100644 --- a/util/meson.build +++ b/util/meson.build @@ -84,6 +84,8 @@ if have_block or have_ga util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-cor= outine-io.c')) util_ss.add(files(f'coroutine-@coroutine_backend@.c')) util_ss.add(files('thread-pool.c', 'qemu-timer.c')) +endif +if have_block or have_ga or have_user util_ss.add(files('qemu-sockets.c')) endif if have_block --=20 2.47.1