From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1texdv-0004Ci-4m for mharc-qemu-rust@gnu.org; Mon, 03 Feb 2025 09:41:43 -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 1texdZ-0003pL-C1 for qemu-rust@nongnu.org; Mon, 03 Feb 2025 09:41:21 -0500 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1texdG-0002Sd-JH for qemu-rust@nongnu.org; Mon, 03 Feb 2025 09:41:21 -0500 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-aaf900cc7fbso970380066b.3 for ; Mon, 03 Feb 2025 06:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738593661; x=1739198461; 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=+6N9ryvNx2tTT6HdSFLFKVlKftlNVXYRqQdp7SLQm3o=; b=m/cZ7HPpkdKAqBdfoXW/kFoIg8MkBsNFYWBlmLbcP8UYigF01sHNbRQTlqunWobX+m ztIiPzaJnVr80A/hEYl4fMV/BWMsIZYULbeFy3PhMod+Sh4AOejPYn8ugfrZQWx75vBy 64sqqMFzPWCJH7ko2sBEAtLnKtL2b2Mhd3X0L8qqK8xdI9c9t112IVFwAl6+wKn2I6bK r3bK+F2u/CHopPS9DY26qZYlppRgXQMjjC5qIWWc5ilZAiy3dUMfhzkddKhBYRdToQXo i9mBGuZOaQ0/UQR+TxLrj31A1z5+lXRHK3wgqSMQhwnzQ8W8IMMcK7G0vayVdGusNTYk q1gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738593661; x=1739198461; 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=+6N9ryvNx2tTT6HdSFLFKVlKftlNVXYRqQdp7SLQm3o=; b=QSmtPFeIrRkThDpY1HixAVbY6uuw4lPiSG2VeEy42G+21zuUp079kf4P42rBKoJ7IH BG4vWNUFPKH20h7qKP7n7xVBXIbvULATNL9rUdBw36fhII+pAPcTjx/5zG85xaJjPDZx vm99BB7eTE/+XgoOXSxiOAjztCO0tFw3D/25JkOU4lHrrVhSrTWrZ6vDBTZAbFeAWI53 wNXVeDnq8dpel/8w8mnSfLZLU8Cyl/4K/LSbLK3TcBLUcrNBjEMnRdUX6vfNdghnIdIZ EFvFrikYStqEcDxNST0MTVh2PHYHKs5hOI+9biVn/mhLypm75oyLprUJHOdka2mRxdkD OgiA== X-Forwarded-Encrypted: i=1; AJvYcCVCK+g+RqvYWKOyHwo5sio5VNtqlAXbnVoYCpF7UK5useOe8bGGSI/t+dDhX6VxrMEC7jejd5vh8gw=@nongnu.org X-Gm-Message-State: AOJu0YyyO7bHdtaoVg47RXT+xh0twgmnkQTOkzUuVmTQDxOPmGZpnqks U/xhreI7O5sphWi8Zy8e/oNNDnjehvXMdgt21mL+VNynK9+ypfFZl47AmG2H70Y= X-Gm-Gg: ASbGnctx9nxPyTxkbBxF+G8oE4ukYycT/0wORnEkkg9Hrh0tmWp4QiditVl8MoYHPfM rRNbTOSIa/M/YWCejccsE4KFEQoW89HiLiWsaOOCAHLIOGRxUmsvAVnCkiz8hKdPUCCiHmuG8EG L3zkE1JYlU4k4WAQUtk+JHSXo7a8uRiZogldl03OmjflVM4/+Wwu0VC+Qh6YJ5BR+yL/3o3uX8k XHM0ywhUhuYW50D9bRwqP/npeOyG1fp/3SV9tTpbJpHDEsbNAWrPeLWPPHnCd5pw2UxMiU1YBxP fHwdKcsVYh6W2MFUew== X-Google-Smtp-Source: AGHT+IHubMLubx4nwLSVuxzF7Wq0eWGnW/dzSLvKqvDK9sZ9EnBQNN9NebJo2lc6HX9/V41iBsZ7dA== X-Received: by 2002:a17:906:c146:b0:aa6:1e9a:e45a with SMTP id a640c23a62f3a-ab6cfdbc62cmr2220431966b.46.1738593660687; Mon, 03 Feb 2025 06:41:00 -0800 (PST) Received: from draig.lan ([185.126.160.109]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6e47d0feasm777494766b.52.2025.02.03.06.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 06:40:56 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B9D4A608B4; Mon, 3 Feb 2025 14:40:49 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, Mahmoud Mandour , Thomas Huth , Daniel Henrique Barboza , Alistair Francis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Hao Wu , Peter Xu , Warner Losh , Pierrick Bouvier , qemu-arm@nongnu.org, Harsh Prateek Bora , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt , Kyle Evans , Laurent Vivier , Riku Voipio , Bin Meng , qemu-rust@nongnu.org, Laurent Vivier , Liu Zhiwei , Weiwei Li , qemu-riscv@nongnu.org, Fabiano Rosas , Tyrone Ting , Paolo Bonzini , Nicholas Piggin , Alexandre Iooss , Ilya Leoshkevich Subject: [PATCH 11/18] gdbstub: Try unlinking the unix socket before binding Date: Mon, 3 Feb 2025 14:40:41 +0000 Message-Id: <20250203144048.2131117-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250203144048.2131117-1-alex.bennee@linaro.org> References: <20250203144048.2131117-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62e.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Feb 2025 14:41:21 -0000 From: Ilya Leoshkevich 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ée Message-Id: <20250117001542.8290-3-iii@linux.ibm.com> Signed-off-by: Alex Bennée --- gdbstub/user.c | 29 +++-------------------------- stubs/monitor-fd.c | 9 +++++++++ stubs/meson.build | 2 ++ 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 fd29d595f4..8225b70280 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -315,12 +315,10 @@ static bool gdb_accept_socket(int gdb_fd) return true; } -static int gdbserver_open_socket(const char *path) +static int gdbserver_open_socket(const char *path, Error **errp) { g_autoptr(GString) buf = g_string_new(""); - struct sockaddr_un sockaddr = {}; char *pid_placeholder; - int fd, ret; pid_placeholder = strstr(path, "%d"); if (pid_placeholder != NULL) { @@ -330,28 +328,7 @@ static int gdbserver_open_socket(const char *path) path = buf->str; } - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) { - perror("create socket"); - return -1; - } - - sockaddr.sun_family = AF_UNIX; - pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path); - ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); - if (ret < 0) { - perror("bind socket"); - close(fd); - return -1; - } - ret = listen(fd, 1); - if (ret < 0) { - perror("listen socket"); - close(fd); - return -1; - } - - return fd; + return unix_listen(path, errp); } 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 = gdbserver_open_port(port, errp); } else { - gdb_fd = gdbserver_open_socket(port_or_path); + gdb_fd = gdbserver_open_socket(port_or_path, errp); } if (gdb_fd < 0) { diff --git a/stubs/monitor-fd.c b/stubs/monitor-fd.c new file mode 100644 index 0000000000..9bb6749885 --- /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/stubs/meson.build b/stubs/meson.build index a8b3aeb564..b0fee37e05 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -61,6 +61,8 @@ if have_user if not have_system stub_ss.add(files('qdev.c')) endif + + stub_ss.add(files('monitor-fd.c')) endif if have_system diff --git a/util/meson.build b/util/meson.build index 5d8bef9891..780b5977a8 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-coroutine-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 -- 2.39.5