From nobody Wed Nov 18 14:40:35 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 4jV45f1nZnz71q7V; Wed, 18 Nov 2026 14:40:38 +0000 (UTC) (envelope-from markj@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 4jV45f1DGgz4FDl; Wed, 18 Nov 2026 14:40:38 +0000 (UTC) (envelope-from markj@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795012838; 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=QTqdAObuuherUq4Ir5IZrYkL+P6RZdoKjo2AAtn7CTs=; b=Z2dq01DLt+/RZqNYtFTLqaPIhCzp79WMkt+jvyJP0AhPEQu7XopNfXDlAWJS3vkmzVgYMG rw8AMmtkfeds842hz4RidGjsmNsSHqpf/FDH2XSBWLyjG3nJV/DMOAQo3tdy6amECI41i5 VaV2lzH7sDqrz86d5OiRYlPoBBB4a/UdTx8XpSl9lSNTrp/x8QD9J0AFa40JlnRbbyFMlj QQe6W9uyLjhK7jVe4+Iws1ROMPYear2m2Fr5OGhxYdA1vgmPNBACFQF4DE4DQcschigLS9 YGcutEp86+vBEeBOPrdnHUiAHTXcWPEWPQ9p0r/ZLnET5oBeYiZ5jRRmbXV18g== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795012838; b=EluPrHk9wG3FMtmth7hoVsGJZGHunw3RBV7YH14gwgChf7WrQ5LcXeqBzJAgE+E7gNz3M7 WjgXMmZL7wvKla6E5P34xqgtRUL7CuHHj2mu5U3hkiHQIG3QFjNpfZGkq/HjRyxUv7sJSg 8Y4yWftdJtd7jjH10QxzJiuj5PpWMdQmoiu3QOH+z8Ln8YIcQnIt2cuqMAG7ptMMM0klV2 Ma7efZzXIzyoeZywQG/uNIJl4T0tMayyaogvoDWh5A5rxrBkJl/i4GqSUr2LvDlNezR5MS G0pw8XjNDhHbFvrQUsBKy3gCoUMZW7oNjBPbvy7fo8S9FQNnQFfQoZHh+sNQbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795012838; 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=QTqdAObuuherUq4Ir5IZrYkL+P6RZdoKjo2AAtn7CTs=; b=L9OEk6hGXpfWNti0+pZcqdilxzQ7k3njcMfjZfNxXLvnKMNfHaBqWnwO1aiu1EB6ThiKZX +iafZCHWzJojtY2h0OhcmGNeaJ637sgNuWNmcO/BwipndkW97ptl/WluHKwOjJ1YHozxJ3 9z1c1Ko0bTdzJ7VRsnEz1vKH3GviGs051PdlaciFmGdlLkmdd3ps3LFfQ1+EWMN4R9Y7g3 roMvcB60+zUtzQCQDiNJ2289epZUs3xgAd3+2TyzIwLGAUCqBFsxiqV9er0+QaWOipwVDp 9yjwakNM8HqYxq/SNfDKWBWuo4IKhep/e4ZRvxqTSXum822JI3VJBIxOFR+Cyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from nuc (198-84-224-249.cpe.teksavvy.com [198.84.224.249]) (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: markj) by smtp.freebsd.org (Postfix) with ESMTPSA id 4jV45d62Kyzwqb; Wed, 18 Nov 2026 14:40:37 +0000 (UTC) (envelope-from markj@freebsd.org) Date: Wed, 18 Nov 2026 09:40:35 -0500 From: Mark Johnston To: Gleb Smirnoff 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 06:14:12PM -0800, Gleb Smirnoff wrote: > 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. How? The exploitability arises from the type confusion that happens when a socket is converted to a listening socket. For instance, one exploit for the race fixed here is achieved by abusing the fact that the sol_sbrcv_timeo and sol_sbsnd_timeo fields cover a data socket's mbuf queue pointers. I'm sure some races existed before the union was added, but as far as I know they were benign. For instance, what happens if unp_dispose() is called on a listening socket, but there is no union? It would simply observe that the socket buffers are empty and harmlessly set SBS_CANTRCVMORE. > > 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. I think it's probably useful, but without more details I can't see how it would have helped here. Note that uipc_shutdown() dropped all locks in order to acquire the socket buffer I/O lock, and that's where the race arises.