From nobody Thu Oct 31 16:49:03 2024 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 4XfVM413BXz5c1QC; Thu, 31 Oct 2024 16:49:04 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XfVM404tHz4jXR; Thu, 31 Oct 2024 16:49:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730393344; 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=RL2EewRvBHVxBaGSA0xyl2nI64IeyFAMPTsQfGOQK0o=; b=YXynFwmnBoaomaA8MXEwSnB6Z2WnqN4wnh6QCa4pQGp1F6mBeR+KiPwbEFjivfhO12HiEo CqdL/TmUr45UI/a+qayqQtEFgntzPL/pSGn3jya1651iTzQ8Bq3F2Z7437W2PwnSDUMG8T TTTJT2uh9m1Nzn+vv3NleLGYPOHM7C2OiIpAeUGFLDY00+oGLIwpJStlPFNkdNqkjkg5Ve fNB/9Zt9Y++czBa3QkohkLLLosUzMLzef/HzmHOW4zb98LZCQYLv47AIammWgVlkZ6X8sw D0725x9lalJguy8ncgdQ1bDYFlk3r+dx2/1hDpO0oW9FOGx930ZFZQ2trAebcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730393344; 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=RL2EewRvBHVxBaGSA0xyl2nI64IeyFAMPTsQfGOQK0o=; b=Nd6ILwQuaKNdUkMwrXGcxWPcDxPPc43OaT0WRNQwqFMVWGLNncl9SwwyjSclOuJrulomN6 iwIbP9aUTBUENH0GS4IL+jOFiZcqxtMYzt2kvTgmtLA0dYkPW+WsZUETS6phS+I1JaZJic Z/7EZruRkiLoGY/y/iuhCi4g32IDXneXISo+rUXzRF20omh9GgmIe16KLDXlnwpVU812kk XmOVyAbzMVLZGvEzzyzVYnVr8LWCljqIkD8TVxmXjgJ/XQPNgvM/VeWsiFZttXblZGDBbs jz4pDRWr01kvIWhkJFNIszLGDMDb3dT5JBsUW3l9yVVR8mdPrWyht+aF14dvVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730393344; a=rsa-sha256; cv=none; b=e5i35JzcDsp7ern+Fga/Mz1QMgLjAHnT6YBs84nebVP563HPRyr9se+C+/RyK9uodVdQVI n04+zjvQUoV48bIQ0Q2MtR2jXbbNZSvVoOYbAfISaoFwog6ee+MNdB6VmcCcDWktIYqHtv uGP6iA0jMiQydxiVGfAG1lCRrh973ABsqCoamLtcyxTPAZGnoiww2B7wD5ebM3c6JQzUKm L+i7JrW/erDm6HxSJakLCWc2DaIOBqlQjz+R3gszL4hdB32iugVBu3JssVk6DSpDVwSlA5 Hbw66mPv2AvQr8Z8hFO6zy1dLjCQFyPJ8AT8PEYGg+Chlb4eqcELWNi+vNu0YA== 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 4XfVM36p0gzkLQ; Thu, 31 Oct 2024 16:49:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49VGn3pZ052274; Thu, 31 Oct 2024 16:49:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49VGn3h3052271; Thu, 31 Oct 2024 16:49:03 GMT (envelope-from git) Date: Thu, 31 Oct 2024 16:49:03 GMT Message-Id: <202410311649.49VGn3h3052271@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: 6421a70e6238 - stable/13 - MAC: improve handling of listening sockets List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6421a70e6238833fed219c756fbe0b914282ff7b Auto-Submitted: auto-generated The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=6421a70e6238833fed219c756fbe0b914282ff7b commit 6421a70e6238833fed219c756fbe0b914282ff7b Author: Michael Tuexen AuthorDate: 2024-09-26 06:06:24 +0000 Commit: Michael Tuexen CommitDate: 2024-10-31 16:48:38 +0000 MAC: improve handling of listening sockets so_peerlabel can only be used when the socket is not listening. Reviewed by: markj Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D46755 (cherry picked from commit 2fb778fab893b4a8a86ecfa20acf2e23bb2cdae8) --- sys/kern/uipc_socket.c | 5 +++++ sys/security/mac/mac_internal.h | 1 + sys/security/mac/mac_socket.c | 19 +++++++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index bcf0ad2ade2c..9cbc5c1f2f7a 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -151,6 +151,7 @@ #include #include +#include #include @@ -936,6 +937,10 @@ solisten_proto(struct socket *so, int backlog) sbrcv_timeo = so->so_rcv.sb_timeo; sbsnd_timeo = so->so_snd.sb_timeo; +#ifdef MAC + mac_socketpeer_label_free(so->so_peerlabel); +#endif + sbdestroy(&so->so_snd, so); sbdestroy(&so->so_rcv, so); sx_destroy(&so->so_snd.sb_sx); diff --git a/sys/security/mac/mac_internal.h b/sys/security/mac/mac_internal.h index d1ee1af09c0b..4b2be98b4e03 100644 --- a/sys/security/mac/mac_internal.h +++ b/sys/security/mac/mac_internal.h @@ -242,6 +242,7 @@ struct label *mac_pipe_label_alloc(void); void mac_pipe_label_free(struct label *label); struct label *mac_socket_label_alloc(int flag); void mac_socket_label_free(struct label *label); +void mac_socketpeer_label_free(struct label *label); struct label *mac_vnode_label_alloc(void); void mac_vnode_label_free(struct label *label); diff --git a/sys/security/mac/mac_socket.c b/sys/security/mac/mac_socket.c index c21f4e148076..da84f2e45fd5 100644 --- a/sys/security/mac/mac_socket.c +++ b/sys/security/mac/mac_socket.c @@ -170,7 +170,7 @@ mac_socket_label_free(struct label *label) mac_labelzone_free(label); } -static void +void mac_socketpeer_label_free(struct label *label) { @@ -185,8 +185,10 @@ mac_socket_destroy(struct socket *so) if (so->so_label != NULL) { mac_socket_label_free(so->so_label); so->so_label = NULL; - mac_socketpeer_label_free(so->so_peerlabel); - so->so_peerlabel = NULL; + if (!SOLISTENING(so)) { + mac_socketpeer_label_free(so->so_peerlabel); + so->so_peerlabel = NULL; + } } } @@ -616,10 +618,15 @@ mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so, buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO); intlabel = mac_socket_label_alloc(M_WAITOK); SOCK_LOCK(so); - mac_socket_copy_label(so->so_peerlabel, intlabel); + if (SOLISTENING(so)) + error = EINVAL; + else + mac_socket_copy_label(so->so_peerlabel, intlabel); SOCK_UNLOCK(so); - error = mac_socketpeer_externalize_label(intlabel, elements, buffer, - mac->m_buflen); + if (error == 0) { + error = mac_socketpeer_externalize_label(intlabel, elements, buffer, + mac->m_buflen); + } mac_socket_label_free(intlabel); if (error == 0) error = copyout(buffer, mac->m_string, strlen(buffer)+1);