From nobody Sat Nov 23 20:37:16 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=1730932677; cv=none; d=zohomail.com; s=zohoarc; b=DOaSMpFvp7BKV1WnLTp4aNgR/fvOuTj1in3IYmZNntHjFO3mRF+gCFxO0qaitkokwJ/PJjkagdYwxB6vc6DbKEG1wro6NhdqKpZS94E6urbrwCkLutjwAFd0Ke/37Lak3en2iLWkUgVfCYKws28CCrUXG1eVdMSN5S4fu0mEX6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730932677; 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=4mhlvfipa+pAxGA6zPLf66uMolrTSoUm2p9Mcz/ybsA=; b=UWE9D+Cj90hZtncI95ZJyLrQoiyfC8gUWf8rfkAdZIEdR9NITcads2AtWPTPt97OSr9AJOLY2m3WJ449IzNYwwcK+0E4VuSjW42qGIYeCJKD78/WKbms0utZTJN1KhcAR3jbf5Fr9VLl2AVSzJaO+FkkjrPCmwDSKnJGoyyledo= 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 17309326779221019.6751749698035; Wed, 6 Nov 2024 14:37:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8odp-0005IT-E4; Wed, 06 Nov 2024 17:36:45 -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 1t8odn-0005I6-Rx for qemu-devel@nongnu.org; Wed, 06 Nov 2024 17:36:43 -0500 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 1t8odm-0005Og-DM for qemu-devel@nongnu.org; Wed, 06 Nov 2024 17:36:43 -0500 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6MA6d7022158; Wed, 6 Nov 2024 22:36:35 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 42rh0rg3ax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 22:36:35 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6MONlt024235; Wed, 6 Nov 2024 22:36:34 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 42nxsyrg43-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 22:36:34 +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 4A6MaWdk29622862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Nov 2024 22:36:32 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A733C2004B; Wed, 6 Nov 2024 22:36:32 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 05D5920043; Wed, 6 Nov 2024 22:36:32 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.171.88.240]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 6 Nov 2024 22:36:31 +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=4mhlvfipa+pAxGA6z PLf66uMolrTSoUm2p9Mcz/ybsA=; b=aPyeV3/Ti0T+dLyh2nut+HnKyqW80f7Fg gcQ1Xr1Yndahs9MUNpSBOrFPI2EK9zgslMjsAalrovF/3EU52/C6a6gmhWNkLmXt RQvCLkV92WG8cWnu99pZk749jP+afWgyFVXiJaUzJgC7wGM+3+GCQ6rKpr7W0oGI GZLVz4WQt9W3p+uFS0kd1zyHiOQe0Adii5Zjlo73C63sVOFsA+mvwR30aWeDPJFo r7bEHGZTczurvA8rcCQC3/awWdSadkCUtNGma9mThuTcLxl36wCtPj7gd7djE1/5 ZaNUjUwjCtBxVWOUJqs6TOHBwFi5Wue24SdTLhDDPEzjIgOAn5D1w== From: Ilya Leoshkevich To: Warner Losh , Riku Voipio , Laurent Vivier , Paolo Bonzini , Richard Henderson Cc: Kyle Evans , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH v2 2/8] gdbstub: Try unlinking the unix socket before binding Date: Wed, 6 Nov 2024 23:31:01 +0100 Message-ID: <20241106223629.2608-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106223629.2608-1-iii@linux.ibm.com> References: <20241106223629.2608-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: tur9UwaPn2Ej6ITIxVnsvdctcacKEtTP X-Proofpoint-GUID: tur9UwaPn2Ej6ITIxVnsvdctcacKEtTP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 mlxscore=0 mlxlogscore=932 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060174 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: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1730932678448116600 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. 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 --- gdbstub/user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdbstub/user.c b/gdbstub/user.c index ef52f249ce9..c900d0a52fe 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -337,6 +337,7 @@ static int gdbserver_open_socket(const char *path) =20 sockaddr.sun_family =3D AF_UNIX; pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path); + unlink(sockaddr.sun_path); ret =3D bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); if (ret < 0) { perror("bind socket"); --=20 2.47.0