From nobody Sat Feb 03 21:10:56 2024 X-Original-To: dev-commits-src-main@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 4TS50J2f2Mz58RFp; Sat, 3 Feb 2024 21:10:56 +0000 (UTC) (envelope-from git@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 4TS50J20pJz4CTM; Sat, 3 Feb 2024 21:10:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706994656; 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=VsGKWoNtRpOlPj0DEyCt8ga7VaeWNJKQ0xEU8CcVCto=; b=Lbcu0ybQPxUCAy+JJ/b6FONOvk8GG0MX7I6Oq5XCxL3OuhGVOF9DOwqCoJ2gSGheQUwL0n 5hcxj3AO9QhusFWGg5HorAjHJa0tlIizmVhfqK9HYhD53uAxAnWEmv3LObzEUUsUChEwPZ hZkueEhzHErpwgirHNoNqVzJOpDddD6fLddkrCzu0yAUU/FdOBypkOVXfocJgW/C4X5tlR TqSy/Nf/L3OwwaV1ltU6S1a2KLwyjQ9CsLzIHAyhhR7O4jkn97UPTCrMad6DjjgK9gwASD zPRs0NZKemvd9F/755+iLWgIMRmJ7HFP86tQRaWdULNB6O0R6CJs5GY9ud90zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706994656; 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=VsGKWoNtRpOlPj0DEyCt8ga7VaeWNJKQ0xEU8CcVCto=; b=rn7XScUbakhQAHlKHsNntuhEfGhGJT+6TNXht5o4l8w4xMs5mcfj4p/7a+y/jleK5ugGo8 NnGuqPBrdmXZi/MGgYfymMke1jCnWKomVjv00eon68zhA03D0Lf0x/Ghpj0oGB1rPuM4Df R39S3TrhSiZ5HPF/CY53lxSWuZ74wZqd0bttX4modQ8u4YJh/Qgh0K1MyomIUd4ON9OJ6o +Id1FyhVc4VwUQ+1uy4OkzpWHRH6YUFJQUn3zUlmKiR+gTJHODb+LYlnEaJFd5ouYoX+gK p6BEaIo6oNY067MeD8aldqnrXcxDZ2Os9TudYEdcO4M8zRw8qL5ce3xlOz1cLA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706994656; a=rsa-sha256; cv=none; b=eNfG7n9ytxiPxyjoHo91xwK1vWpwNlMFuHbp51mz4MWK4nBvsr5DYDZZLl/0fHWLgvvfk+ l7ZFpBEIIm6Vq/FDYiMfnAuSq/b1yISsDY47NMKljNcjo0Vwqv4oozGLCeWyXBtdMZ17xn FGQeNzq6ur3t15q9q0er79K2yqQZPbzqfTmHGp8dWG2ksk5GQPH3Kcg1TjpFaCSc5rp7nK vdixwZjSDRxFxaR90DHiQRce+yfdzI9QsPyiG36cKzGTVp0ghXRphVID/csHnWnB1oKvrS RuzQ9fP35PpvO7t99Wds3aN5fAPY+oPzGJ02rF5kWRBUTj6TakwR8ta3xTnumw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 4TS50J15dLzTFZ; Sat, 3 Feb 2024 21:10:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 413LAuxV093308; Sat, 3 Feb 2024 21:10:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 413LAuoa093305; Sat, 3 Feb 2024 21:10:56 GMT (envelope-from git) Date: Sat, 3 Feb 2024 21:10:56 GMT Message-Id: <202402032110.413LAuoa093305@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: d682c1eaa598 - main - unix: synchronize shutdown(2) with read(2) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d682c1eaa598a6bb4b9b81ba80e8e1202a0c9611 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=d682c1eaa598a6bb4b9b81ba80e8e1202a0c9611 commit d682c1eaa598a6bb4b9b81ba80e8e1202a0c9611 Author: Gleb Smirnoff AuthorDate: 2024-02-03 21:08:41 +0000 Commit: Gleb Smirnoff CommitDate: 2024-02-03 21:08:41 +0000 unix: synchronize shutdown(2) with read(2) unp_dispose() is called on shutdown(2) and thus needs to acquire socket I/O receive sx(9) to synchronize with read(2) that may read top of the buffer without socket buffer mutex. Notice in the last chunk of the diff that the function used to be called with the lock already acquired in the past. --- sys/kern/uipc_usrreq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 976490dbe2d8..a9a7dd3a1189 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -3217,6 +3217,7 @@ unp_dispose(struct socket *so) struct sockbuf *sb; struct unpcb *unp; struct mbuf *m; + int error __diagused; MPASS(!SOLISTENING(so)); @@ -3228,6 +3229,8 @@ unp_dispose(struct socket *so) /* * Grab our special mbufs before calling sbrelease(). */ + error = SOCK_IO_RECV_LOCK(so, SBL_WAIT | SBL_NOINTR); + MPASS(!error); SOCK_RECVBUF_LOCK(so); switch (so->so_type) { case SOCK_DGRAM: @@ -3279,8 +3282,7 @@ unp_dispose(struct socket *so) break; } SOCK_RECVBUF_UNLOCK(so); - if (SOCK_IO_RECV_OWNED(so)) - SOCK_IO_RECV_UNLOCK(so); + SOCK_IO_RECV_UNLOCK(so); if (m != NULL) { unp_scan(m, unp_freerights);