Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2083013pxb; Thu, 4 Nov 2021 13:45:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+kgFNSEf7JSQxrp6YkDyxW3bGFeKCIT1+GwPMDm8KSzYWL3hTqCbLCs1dNPEF0KWpNNZt X-Received: by 2002:a02:a8a:: with SMTP id 132mr5627606jaw.24.1636058751048; Thu, 04 Nov 2021 13:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636058751; cv=none; d=google.com; s=arc-20160816; b=eJT5aLcEu+H7q9LjOS+qMRl/egFERaq7OjWz6u/tKwyLX6fYB5B9kpkwN76jnWpw41 nd4IqZ0RFPAvmgfCgvvI+M8+HXf+8KigTa4h6URXQDIAewjS5BSBaQv/0q8qwMKgsRSF cFDT1P+Oom15PhpCi/F26Kn44Qf8W9a8kUNhu4WBN9mOVq0lsbTUL+QJJL6Z+/NS9UZ/ 12IcchG+AsXq/zvSXS03ydykubQIwEtc2UXBG9eHn9kU9EY9LkxJ8st9Sfg7h99yD2PU wJjfFuWkkhVT5v6r4sLcWl272cqJ6/fm0cl9hTjwiP3UZ++RlbJJdzvTtAE+A+TTgeRT CzLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5ysUK4zlUy4qbvF8xulmXFjW7M2EeOHCxuh+1FxUYgQ=; b=B6ekO2fOPs1LqGHEThHHbPqUa39+omFMlm4CR/wN8izNhuyX5ROXr1FQENmNhC2JJY l6ewWtRM5xEAzmT3fr4b0o7/nBtupexWGxxCFv4gs3CIOXYb0xFSYW6IZi4NSajRqfy7 s9tYrfvkp9+a2IUKf/mpy4YjUWeufeaavWedt4oIFLUaVqa1HtJN/pUYbzsZ2KimR0wq s8zP8nK2pvIPnPaFYNNZCD/xhFxHMVumlIl0RFTICMGt79UydPvpeRex3+TkAKDmKwOx KKaN1BThfN5Rd1SV/fb4zC6AMfLGKgA+BeVznwszUZwulFIGewoyzpmU1bId3popTiLm VqEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="HQ/NEzYk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j16si13293451jat.65.2021.11.04.13.45.36; Thu, 04 Nov 2021 13:45:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="HQ/NEzYk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231993AbhKDUCb (ORCPT + 99 others); Thu, 4 Nov 2021 16:02:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21229 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbhKDUCa (ORCPT ); Thu, 4 Nov 2021 16:02:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636055991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5ysUK4zlUy4qbvF8xulmXFjW7M2EeOHCxuh+1FxUYgQ=; b=HQ/NEzYkGdhWhXvT4hnNkllhxHqk6yTDcgKOWcKIIbXAVepaQCcXwQFI49LXI3XVbvQ4N/ jUMsF3f4BBWFbyTyg64m84F1wutAk6FrESAwZ16OgnaEMcFlka9YjcmvJsNKncqA1Y7Sfr yKQIVEzTpTlFnteqindsD77vdBFoCW8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-Fsh7rwQcP9WFK_iypOiVtg-1; Thu, 04 Nov 2021 15:59:50 -0400 X-MC-Unique: Fsh7rwQcP9WFK_iypOiVtg-1 Received: by mail-ed1-f72.google.com with SMTP id w12-20020a056402268c00b003e2ab5a3370so6843051edd.0 for ; Thu, 04 Nov 2021 12:59:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5ysUK4zlUy4qbvF8xulmXFjW7M2EeOHCxuh+1FxUYgQ=; b=3u6hgGK/qV5DjQqF5lwJRULo7X235Z/fDV34mXXhqi42I/Jdfw6jzBFzlXYnaGSM9S Rz+vnA7BXSfhkXUwaGZ+7RjwIb0uaHhuny+yOpYgfT2AmUVJ065mE4kt5u1wE4rPhH1A PZSdKlqnAsOxQx9xp1vtIlBChQ4RiEXNO8KZm3LBfjyCU6fE78LZU+Ci9X0yTi8dWnL8 Hbc4Vuk8QV6iRE1u69WSsjPuS6KxWzTi2l1H6vDhYbntTTpZNniWfEBgreJheSjYBSTM ZfRobgYMjE4NpCNhkeFVyPQ7xX/Q1CdwI9zSou08awHgodkmOWnJ5qnuT4XmYpR6SY/y +1BA== X-Gm-Message-State: AOAM532gNlqz2mfl3/X5VAkNUmFfHyOKlN46v1VZw0FsSJ1W6asZIGyE tSBRrpIF+BHNP9CsY4FINETqL3njT2tj6lDn1Mvk3L94aXrs8s65kww0tw+DVjniZFFAv1Pf5hX KP+BGSSY3MAlMB0dYEQaTEqJ6 X-Received: by 2002:a17:906:c9cb:: with SMTP id hk11mr64150292ejb.204.1636055989310; Thu, 04 Nov 2021 12:59:49 -0700 (PDT) X-Received: by 2002:a17:906:c9cb:: with SMTP id hk11mr64150267ejb.204.1636055989131; Thu, 04 Nov 2021 12:59:49 -0700 (PDT) Received: from localhost.localdomain ([2a02:8308:b105:dd00:d067:83f0:d612:b70f]) by smtp.gmail.com with ESMTPSA id p3sm3096445ejy.94.2021.11.04.12.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 12:59:48 -0700 (PDT) From: Ondrej Mosnacek To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org Cc: Xin Long , Paul Moore , Richard Haines , Vlad Yasevich , Neil Horman , Marcelo Ricardo Leitner , linux-sctp@vger.kernel.org, selinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net] selinux: fix SCTP client peeloff socket labeling Date: Thu, 4 Nov 2021 20:59:49 +0100 Message-Id: <20211104195949.135374-1-omosnace@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit referenced in the "Fixes" tag mistakenly attempted to preserve the label of the peeloff socket that had been set in selinux_socket_post_create() in the case of a client socket. However, the peeloff socket should in fact just inherit the label from the parent socket. In practice these labels are usually the same, but they may differ when setsockcreatecon(3) or socket type transition rules are involved. The fact that selinux_socket_[post_]create() are called on the peeloff socket is actually not what should be happening (it is a side effect of sctp_do_peeloff() using socket_create() to create the socket, which calls the aforementioned LSM hooks). A patch to fix this is being worked on. In the meanwhile, at least fix sctp_assoc_established() to set asoc->secid to the socket's sid and selinux_sctp_sk_clone() to unconditionally get the peeloff socket's sid from asoc->secid, which will ensure that the peeloff socket gets the right label in case of both client and server SCTP socket. The label set by selinux_socket_post_create() will be simply overwritten in both cases, as was the case before the commit this patch is fixing. Passed both the selinux-testsuite (with client peeloff tests added) and the SCTP functional test suite from lksctp-tools. Fixes: e7310c94024c ("security: implement sctp_assoc_established hook in selinux") Based-on-patch-by: Xin Long Signed-off-by: Ondrej Mosnacek --- As agreed with Xin Long, I'm posting this fix up instead of him. I am now fairly convinced that this is the right way to deal with the immediate problem of client peeloff socket labeling. I'll work on addressing the side problem regarding selinux_socket_post_create() being called on the peeloff sockets separately. Please don't merge this patch without an ack from Paul, as it seems we haven't reached an overall consensus yet. security/selinux/hooks.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 5e5215fe2e83..5d9da4662449 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -5502,8 +5502,7 @@ static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk if (!selinux_policycap_extsockclass()) return selinux_sk_clone_security(sk, newsk); - if (asoc->secid != SECSID_WILD) - newsksec->sid = asoc->secid; + newsksec->sid = asoc->secid; newsksec->peer_sid = asoc->peer_secid; newsksec->sclass = sksec->sclass; selinux_netlbl_sctp_sk_clone(sk, newsk); @@ -5566,7 +5565,7 @@ static void selinux_sctp_assoc_established(struct sctp_association *asoc, selinux_inet_conn_established(asoc->base.sk, skb); asoc->peer_secid = sksec->peer_sid; - asoc->secid = SECSID_WILD; + asoc->secid = sksec->sid; } static int selinux_secmark_relabel_packet(u32 sid) -- 2.31.1