From nobody Wed Nov 18 02:14:12 2026 X-Original-To: dev-commits-src-all@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 4jTlXV6J4Fz719xD; Wed, 18 Nov 2026 02:14:18 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTlXR5gswz3MGt; Wed, 18 Nov 2026 02:14:15 +0000 (UTC) (envelope-from glebius@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794968055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZtnRZZ+NKowJSLkT6abw/b+6OX0jh+jYMKcEY05thbM=; b=YBw12tr+nvGDud18a8+6DrmGxRdJNG22rhd+n0Zud/SACeqRXnwv2V9Hu8zJjg5sQkIxU5 csbdxh079I5AqgsKUpS5Mt7UA56LDyr38Aflp5BDITqLLs2945DavIgepQTbQApC47/uIw MBeLwCbF97KMNXykQ0TDjxAOHA4WDe6KH2q2Cuxl7A5w2BMs2IN0BzYmJO61aJmYo/I+ve JgZN4iUlshAt0UIzhARnKBsJQw1Opt5HM9MZsOVO7aWlDFMsOmU5mluz7ay0XQHsxVwpBH /b9KW/poqi20fTlI5HCHIeLyjGnC00Wlh7PiVaBEHLHEfLNYJLCpMJ4X7QJ3fA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794968055; b=wvJDn2/wDAn3s0AmgNnnXEtrk4vkjwSFWmV5xEiZTahqWApZCnxaJp2R7pXVSlR93VzVp1 iXO3j1rtQ1JCoL5uiOBvfUsVz6uXsStWxjgAdVUZvxhDnnlIIGDA7T/veRXfGjzc4pC3tj +BykJEHKi/pCCxGDq8GZ8EidR2fPQI69jqy420W9gF7fQTEhthsJF1Hxxs6Pqh7dCym10C sWRtTkSC3HUVWi1UMlp1Kj+RAB+S9G7u46eY0d4mZ0sDfhn0dYV8IZ3rX9+/KzPgPYnd5V geiErPyPOlXwdfvDpXPbpQ5uARrG0IWRADFNyUfr3nlEt5o3A2yAe4A+5DD7lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794968055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZtnRZZ+NKowJSLkT6abw/b+6OX0jh+jYMKcEY05thbM=; b=hEUjXFgl8rrTPt+JmotL5rap28WAz4RLlixxkgtopIUUYQy8QTkTGmyXGm6iYzUrOL+HT+ bT0mtwIloXNnYB4s6GeqpK//NJcpQTdQxcqrVgnoWnVuxzGUPziLZl6+wRnJr5wen1eN2g 1g2ylmxMg6pVuufx7cRE0cFxj+Ak5YCn9oo0omqpMIi2x6ZjH7iDoMdK+Z8DvSDcY8Sw3s BnEv60lzeYCcFNyQw26t4MRU8TZ7mE4yKfRPS3KyYId56/McxcrIcL6MVIkt1RrT0addKR hOrOKW7wSeVlBuUnDYYI1GXs/6+ZqESl/K6kOXYX1GvTsiExhGSJ4pM6cBiopQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from cell.glebi.us (glebi.us [162.251.186.162]) (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) (Authenticated sender: glebius) by smtp.freebsd.org (Postfix) with ESMTPSA id 4jTlXR1BCNzfkN; Wed, 18 Nov 2026 02:14:15 +0000 (UTC) (envelope-from glebius@freebsd.org) Date: Tue, 17 Nov 2026 18:14:12 -0800 From: Gleb Smirnoff To: Mark Johnston Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 6144315d1612 - main - unix: Fix a race between shutdown and listen Message-ID: References: <6afc887d.1ced7.733cf5d4@gitrepo.freebsd.org> List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Nov 17, 2026 at 04:28:36PM -0500, Mark Johnston wrote: M> > I wonder if this could be avoided if we had pr_lock method and more streamlined M> > operation of listen(2). Maybe revisit https://reviews.freebsd.org/D48709 ? M> M> Really a lot of these problems come from the fact that we started M> overlaying listening socket fields over top of regular socket buffer M> fields, as an optimization to shrink struct socket. struct socket M> effectively represents two different types. Then, since listen(2) can M> be called at any time, any code which handles sockets has to be very M> careful to make sure the socket type can't flip. We've had more than M> one bug due to this. M> M> pr_lock might make the synchronization rules a bit simpler, but the M> underlying problem is the potential for type confusion between data M> sockets and listening sockets. Even with simpler locking rules, it's M> too easy to miss an SOLISTENING() check somewhere. So probably the M> distinction between listening sockets and data sockets needs to be M> reflected in the type system, e.g., have a separate DTYPE_LSOCKET file M> type and struct lsocket type, and make listen() convert an existing data M> socket to that type. Fail if the underlying file structure is M> concurrently referenced by a different thread, or if it can't be M> converted atomically with respect to fget() lookups. I'm not sure how M> challenging that would be to implement. I was thinking of switching dtype, but found out it it impossible to do it safely without stopping all threads. I agree that lot's of places that need a check for a socket being listening were missed in the initial version. My fault. However, I don't think the overlaying has anything to do with a race between listen(2) and other syscalls. The union just makes a crash a more probable result of a race than a misbehavior. The races were here before the union, and I'd guess some even could be exploitable. So, back to D48709. I think it is worth giving the generic socket layer a method to tell the protocol "please lock/unlock the pcb". Not only listen(2) may use it. -- Gleb Smirnoff