From nobody Thu Feb 24 16:46:05 2022 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A3B4F19E37FD for ; Thu, 24 Feb 2022 16:46:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K4Jgx2Nx0z3MxL for ; Thu, 24 Feb 2022 16:46:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2EB387AD4 for ; Thu, 24 Feb 2022 16:46:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 21OGk57I035538 for ; Thu, 24 Feb 2022 16:46:05 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 21OGk5qb035537 for bugs@FreeBSD.org; Thu, 24 Feb 2022 16:46:05 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 262172] UNIX Domain bind() - distinguish between random garbage and alive listening socket Date: Thu, 24 Feb 2022 16:46:05 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: firk@cantconnect.ru X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645721165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3TleAAAWzzNlLnkoP07HiA4u0Wp8H0NRTbRb07nwm2Y=; b=p0r2awwoGBiPvgCRzDGnHS93sp7V1jnw2ldEgfYhmw3KC4lBFOMvrBgUagxdayRsATVfox eerwd/OwFvY1rH71D5rdO0YLG+lBiOzm9Tjyv5xXD/68fB5bExoO2Im0KBiwLWwVvzTbW4 5PP0X53Gfxw5sOGEypkHdkHPU8R/PaTwizBaLfvHlJQaPjMUDBZvZ69lDZzRfjLhaIhPVk asoTdAMTBwwcuUfVXJZ22TRJSYRBAZwlt2kQagd9s1INcIDhNFdPJUkRUm4/Livg9jKJDA /AKZ53bbaMoTCFTW5xsCxcdDSqNp4QPNuGJl9wHCItTByR6Fwoj+T6pE5pEe8A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645721165; a=rsa-sha256; cv=none; b=ycUJzdX6v90dB4eiNBg98B1PolPkmo3o5nDDg3h+S29IpssA08jSPPw/mzQtafe5F3Ovxm v6ALyxbeBaxJm7ruRXYS1q+XUZ9NTD7zj13sF7ffV17fZ/eLFixsf5ZLyq8RHI+e0Fno1n xiTEhvPm5jUishNgKHz7gge3YwsqKYX/QFBdyTemBIfG5vD8GLFTnp7b+qYH0ODEXgSKOI VTl6m5Zqn3o/NPGDsxpeSBBwfDP/0MUECzFO+EpFJ6g1Hfoid77YiNYJOse9OEtJrLU2fz yW/wfeqxofO2oTyKogZYW4lYUX1hzyu1gSZ2QufwOMXBafAb5lAiA7+K26Z5Xg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D262172 Bug ID: 262172 Summary: UNIX Domain bind() - distinguish between random garbage and alive listening socket Product: Base System Version: Unspecified Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: firk@cantconnect.ru Created attachment 232076 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D232076&action= =3Dedit patch for 12.3 The bind()/bindat() syscall for AF_UNIX returns EADDRINUSE when some file already exist at the specified path. EADDRINUSE should mean "this address already bound to someone", and this is not always true here. There may be j= ust some file (not a socket) or a dead socket (pending non-unlinked vnode from already closed, previously bound socket). While the first case usually considered as an application error, the second usually means "we need to re= move this stale entry and try again", but to do this we should first check if the socket is really dead. There is a hacky way to do this: try to connect to it, and see what happens, but: 1) it is an extra unneeded system call, 2) is the socket is not dead, the listening application will receive spurio= us connection request, which is not always desirable, 3) there is a problem to distinguish between ECONNREFUSED from a dead socket and ECONNREFUSED from full-backlog; we can try to connect with a wrong prot= ocol (SOCK_STREAM vs SOCK_DGRAM etc) to get another errno, but anyway it is a ha= ck So I made a patch to return EEXIST instead or EADDRINUSE when there is not really bound socket but just a random file or a dead socket. As this may ca= use some incompatibilities, I added sysctl to optionally enable this feature. --=20 You are receiving this mail because: You are the assignee for the bug.=