From patchwork Mon Feb 10 16:14:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 863793 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e42:0:b0:385:e875:8a9e with SMTP id r2csp1676387wrt; Mon, 10 Feb 2025 08:17:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW+kmzA4l8c4a+Pfd4yW+GqFXTAv5h30I+ErjymE18205OwJGSTLKoJH3Ybjt3mDpwYH9fd6w==@linaro.org X-Google-Smtp-Source: AGHT+IH3WnZheUGM3RDnRdnOyrSfLLVAhre+ITBjJrP1EYU+mr/O22BG+JWWiWn0vBoC4uhYw8wM X-Received: by 2002:ac8:5812:0:b0:467:681c:425c with SMTP id d75a77b69052e-471679a8fe8mr209671641cf.1.1739204267756; Mon, 10 Feb 2025 08:17:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739204267; cv=none; d=google.com; s=arc-20240605; b=RIPHq7k5mRLzryE3IgQSg3vWU83AEgQ3gXZODz0cr5Div2iINox1+oqD3bv5rkP76E /EnYYWAA5iAzlSbJqExg0eGZRndXd0FSrnCmKtavpl5k98QM8WzBKoC6bdb5bZIZPAwV JiqPFo9KqrB6Ucr85PMxXVp0QHE7/1OyEkJXBqJveONPRPKpIF866UUWwQ1xuZoePB21 /AutRtP9ZOx7uW2D6VmwlUtaXLpj1a3LCoOgu//CViopT2K1BYqibVyAxfbBDBEYrley VDmgTlT4bnVvB73OaIZHB4pFiYzwaCGVoRZ6EWtW6Tl3pDoYzj9ac4My5yoCkTv1YSUN 51pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YT3MtmnSLkBKcOVyMB0JztX76L81nkooZxZXsqcklIs=; fh=zNcCrv0iORvx7Yv7ZHmrW/HP3e3F04qVdXctlpWMV5E=; b=CSJcGh7DytFVp6LNb257XhB/VcTZn7FUj88hqbAG4G05dYbuDYULuqZQrwKLL9SBVP ycSMK3akteSBJ13BMEUUVSioWIjyzjkCgNosqh19+/sk1PXeOu7+Ws0iI6T/TiboZ+8Z r4c+stNgOPTqRsPQaUlk9HC0KmaYzRb2QLUTtNiRQspr3EaVfjyCdB0VhQFBFdwTb1mB YfI5F+yKNBx5tExD9KpLs25lId21c3+5TYWDaF4fSthPgI0L1eB8HaNgTXQYR8AErPuq 5lDUdNGSPTt/jdQLwR/S66FDYqCDW5D+Z59WKrl0dpO1Mz5U/NsM0bLL36Prce3MF6iC gnJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ct6YfJaK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c05837b43esi375727585a.369.2025.02.10.08.17.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Feb 2025 08:17:47 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ct6YfJaK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thWSD-0006wV-EL; Mon, 10 Feb 2025 11:16:13 -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 1thWRB-0004NX-Cy for qemu-devel@nongnu.org; Mon, 10 Feb 2025 11:15:09 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1thWR6-0001XJ-PJ for qemu-devel@nongnu.org; Mon, 10 Feb 2025 11:15:08 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-ab7b80326cdso238870466b.3 for ; Mon, 10 Feb 2025 08:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739204103; x=1739808903; 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=YT3MtmnSLkBKcOVyMB0JztX76L81nkooZxZXsqcklIs=; b=Ct6YfJaKa2Ka+A34mWwgmMA+wEpIwQ4BUKa6BNZFJeUrC6J1TX9AwuFAgCbs3ZlPzj LlTtmRZguks4MXGkHuIWsDX7czsGfjZjEDp6qewwqW0RKLjZ92/iRuMz2ppu30pyW++P pMqrdE9cFuQKgxVEnWWKekRBQhL7DReHuvIGv6j92gksid+gW53LYPn6eKnYorXjc39I DLqMY4ELq+uaYm+TKdGH+v8puMYrZhUVeNF2RZTgBKMQ1q97lqQ8tA4hpV+PfaunLtHQ x8TMbr4pjJGlGPmX1krY8kWJsySiVQmpyzuoxsOqoMZ4uIiKqfv/OsdivE29TPi97G29 VExg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739204103; x=1739808903; 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=YT3MtmnSLkBKcOVyMB0JztX76L81nkooZxZXsqcklIs=; b=VVSlTx5IHT0S3q8byaxdJw+KSFqOIpMTSpm26RL7QsgAhRSeBJ2yDvW8hxXjF3tmF2 X3hhqLeNIS2+/apWZOs0Gte2ohP+PB/6h/KaqIP8VlzzUkhtiPNw7tXCy/94cdpB+D5B XZPdH39ubT2gfZS0Y+0+BSVUKQgZGj6Hp5F5IXmvAPBDQTCM2ZNj5ZNYkdhLZcM5Jipj lHxCWA2C5/1dvlDLDJ6DedHek+qG9CKATu9xbAfjw/RzZ2Cv+kB+a/DwMARELVNDJcZn 5goazC5/JgfxuKkKVmBqS3G11rn25skdL9+ZUm/L5d7hMCJIf3FS6ubs2ScvktrrBQgN /dGQ== X-Gm-Message-State: AOJu0YwzHQdZzwFmA7zo44znOW/ZLvTaXKiRCV7qOsd/bT2xgTglWS2c lB4/4pCKerxch4g5TwAtQfCmdewJB8wpfuews4hcJy4ZsLuGQat5ka47bPCUHr8= X-Gm-Gg: ASbGncso+SUnY8t0oTxhCeymgXtU238aWMEc/oUwQLZgtIJHDc05k2+l31PZYNyLrd4 J3k+PYYN5fnDr1erSqXokiIU9wfgqHFI9Wau4bsSKtTPYolbNh8yGiZTUmVFliX5oZF06AX9Z8f 63obx0pewKFBvNptqCx6aQgyqe6FteDCP4A/DOVLmJ+k+fXsGMOnEqePFB9phHpFEQmpOKqoMM9 Or4IX6uZQnD/0vw5f2498R4920VULzwy4811SQKaZNw/Zr/TaCTworfPcNDx4rL9591G0zPx501 sVpD4d1vix3H1DZZyw== X-Received: by 2002:a17:907:d92:b0:ab7:b068:c7b9 with SMTP id a640c23a62f3a-ab7b068c7d9mr696240266b.13.1739204103126; Mon, 10 Feb 2025 08:15:03 -0800 (PST) Received: from draig.lan ([185.126.160.109]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7bbf40b2bsm291680466b.23.2025.02.10.08.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 08:15:00 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C773960354; Mon, 10 Feb 2025 16:14:52 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PULL 11/17] gdbstub: Try unlinking the unix socket before binding Date: Mon, 10 Feb 2025 16:14:45 +0000 Message-Id: <20250210161451.3273284-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250210161451.3273284-1-alex.bennee@linaro.org> References: <20250210161451.3273284-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 Message-Id: <20250207153112.3939799-12-alex.bennee@linaro.org> 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