Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp755777pxb; Thu, 21 Oct 2021 08:54:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxd7C6RuyuNihCT/624hlH7BRuf01MfECD8i4OwlnehyupvDe4vqxDmTIdCB/YuxkRWClNv X-Received: by 2002:a17:907:7f8e:: with SMTP id qk14mr8277991ejc.91.1634831682746; Thu, 21 Oct 2021 08:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634831682; cv=none; d=google.com; s=arc-20160816; b=akZG6L7MXBk/7Z11G667Vb4duTV+UaF5fgRY2C+fffhOnBjMQSCirpaJ6wwLcPGc6r TqQIk5dA9lmm2pK4GHsJIiutVOEi2NbAaDWuwr65JgWknYv7xERkhBI1nXWBJsC6Vnee 1lCCu2OhfRRB8pUSRj0BdWI8cSpbDU0dsRa477YPAg0zdOFYG0t3fkKivFwcVsx90dpx mCjAv98DBptcC4LNuHfP+JYRVVOAmDs6vwhB0KaOD7IgKoWZE9epDDXntGzruFLm5/O2 U8xMc60jJLu0JSVlX83eJ7cuL4sfidS17VjpSuxdOGuQc+eMP6Jye13820H2Q8QzDEEa 3v2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=H7h6CP1iZoH++rJfQu43toMYIm9p0CArXFcUD4a+mt4=; b=KRlbRnmOJ4gsDpdWkzwv2Rxqp5+m1WLHdAh1f6iFEmVfSh1Osv96j/w7fbyXDQarkp jIT4XKtrVN8HcF1GMJWwMf8DBJI+IDWknhPDu9icqgNVlyluqpNk2V6FjMt03dqN89bX vWK29exU40DSJ2WWwLd9nktoA5j5JgDBygn/NE6Jv0NuZsJ4y5sMFAsK903HILplS+cS +rjzwsWZFgInZo6tvCHn/osLDoByi87x+wERvulymp+rcuh5hl+GJ/+CmSqAE4Mg+yVg I8/gUqqhYCgM4VI6Tdqff0/IgI/H80IsepJ05kQO51drWlVA0sq0MddN4/YpbSE4jvtk FR7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RhFERS//"; 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 h18si7340344eja.209.2021.10.21.08.54.19; Thu, 21 Oct 2021 08:54:42 -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="RhFERS//"; 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 S231771AbhJUPyq (ORCPT + 99 others); Thu, 21 Oct 2021 11:54:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56829 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbhJUPyp (ORCPT ); Thu, 21 Oct 2021 11:54:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634831549; 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=H7h6CP1iZoH++rJfQu43toMYIm9p0CArXFcUD4a+mt4=; b=RhFERS//N499IiIni5aTCHm6PjRF5vbY7yGmYZ1mF6ld3MGrOvdEhV9nRdPLGR9N/zOaEC MW8ejWAH96PFvIjm1p2soyoZgt6rIoime4kJdCxE1Te6A0nhAcVltXwl5g8Zb2raKrsjsp +9aOB3wnb6yvh8mXQKeiKpH2XyO+EVY= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-AeznImJZPTaqj23H7h7OMQ-1; Thu, 21 Oct 2021 11:52:28 -0400 X-MC-Unique: AeznImJZPTaqj23H7h7OMQ-1 Received: by mail-yb1-f197.google.com with SMTP id t92-20020a25aae5000000b005be785abef0so235416ybi.2 for ; Thu, 21 Oct 2021 08:52:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H7h6CP1iZoH++rJfQu43toMYIm9p0CArXFcUD4a+mt4=; b=QKK23CjjZZ5429kFePPe5rooP4wqUJ7dGIxSKvfB7NnN2sMDHTX3x0kG5s7m/HRdb0 Fm6bP10gNjF+okaA7BslDnkM5Ola9dGqHVKi6fzqRIQDL7im1+ebYlO/3JZVuH8ytX0i D7is+YPd6YYBtDBW4mDGufzSbB9sx/6ZwpbeOiTXVcP4OQFxJUWwgSmqREB3AHn2pDEK 2NchqjigPhNYwFNxAV7QAzhpNxH0D3TNVkJApaSxUFAJUvkovnim0HwSr8sDZA/9BgAA 5Bn/cQ6o1qPc5xTGn3neJf0HMw+S2vxL86nJiP0xcD/6GogHkMIYP7wzicEW8njEtG4J ciXw== X-Gm-Message-State: AOAM533/UJGCnlc2QR2B1YgNX0FvExULI03UNo7yZcsAis1eI+VK2E9l M42F4zblT4dOYDH96NRP1EYKWKMBsfjBotKyOTUjk+jzCCLK2YSDweULNCvBMx1ajfHMj8gv7ah 0nKps0ZkrcDdCrelbWMnO2SQfFNU49+i/ihgS8tFX X-Received: by 2002:a25:2e01:: with SMTP id u1mr6673481ybu.363.1634831547745; Thu, 21 Oct 2021 08:52:27 -0700 (PDT) X-Received: by 2002:a25:2e01:: with SMTP id u1mr6673450ybu.363.1634831547455; Thu, 21 Oct 2021 08:52:27 -0700 (PDT) MIME-Version: 1.0 References: <20211021153846.745289-1-omosnace@redhat.com> In-Reply-To: <20211021153846.745289-1-omosnace@redhat.com> From: Ondrej Mosnacek Date: Thu, 21 Oct 2021 17:52:16 +0200 Message-ID: Subject: Re: [PATCH] sctp: initialize endpoint LSM labels also on the client side To: Vlad Yasevich , Neil Horman , Marcelo Ricardo Leitner Cc: linux-sctp@vger.kernel.org, network dev , SElinux list , Linux Security Module list , Linux kernel mailing list , Richard Haines Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 21, 2021 at 5:38 PM Ondrej Mosnacek wrote: > The secid* fields in struct sctp_endpoint are used to initialize the > labels of a peeloff socket created from the given association. Currently > they are initialized properly when a new association is created on the > server side (upon receiving an INIT packet), but not on the client side. > > As a result, when the client obtains a peeloff socket via > sctp_peeloff(3) under SELinux, it ends up unlabeled, leading to > unexpected denials. > > Fix this by calling the security_sctp_assoc_request() hook also upon > receiving a valid INIT-ACK response from the server, so that the > endpoint labels are properly initialized also on the client side. > > Fixes: 2277c7cd75e3 ("sctp: Add LSM hooks") > Cc: Richard Haines > Signed-off-by: Ondrej Mosnacek > --- > include/net/sctp/structs.h | 11 ++++++----- > net/sctp/sm_statefuns.c | 5 +++++ > 2 files changed, 11 insertions(+), 5 deletions(-) See also the selinux-testsuite [1] patch [2] that verifies this fix (i.e. the new tests fail without this patch and pass with it). Not being very familiar with SCTP, I'm not 100% sure if this fix is correct or complete, so reviews are very much welcome. [1] https://github.com/SELinuxProject/selinux-testsuite/ [2] https://patchwork.kernel.org/project/selinux/patch/20211021144543.740762-1-omosnace@redhat.com/ > > diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h > index 651bba654d77..033a955592dd 100644 > --- a/include/net/sctp/structs.h > +++ b/include/net/sctp/structs.h > @@ -1356,11 +1356,12 @@ struct sctp_endpoint { > > __u8 strreset_enable; > > - /* Security identifiers from incoming (INIT). These are set by > - * security_sctp_assoc_request(). These will only be used by > - * SCTP TCP type sockets and peeled off connections as they > - * cause a new socket to be generated. security_sctp_sk_clone() > - * will then plug these into the new socket. > + /* Security identifiers from incoming (INIT/INIT-ACK). These > + * are set by security_sctp_assoc_request(). These will only > + * be used by SCTP TCP type sockets and peeled off connections > + * as they cause a new socket to be generated. > + * security_sctp_sk_clone() will then plug these into the new > + * socket. > */ > > u32 secid; > diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c > index 32df65f68c12..cb291c7f5fb7 100644 > --- a/net/sctp/sm_statefuns.c > +++ b/net/sctp/sm_statefuns.c > @@ -521,6 +521,11 @@ enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net, > if (!sctp_vtag_verify(chunk, asoc)) > return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); > > + /* Update socket peer label if first association. */ > + if (security_sctp_assoc_request((struct sctp_endpoint *)ep, > + chunk->skb)) > + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); > + > /* 6.10 Bundling > * An endpoint MUST NOT bundle INIT, INIT ACK or > * SHUTDOWN COMPLETE with any other chunks. > -- > 2.31.1 > -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.