From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1BCDC04E53 for ; Wed, 15 May 2019 11:47:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 947322053B for ; Wed, 15 May 2019 11:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557920829; bh=OU8sNd8F8lxRYqqaTc9NVhkBLTtyB79LwudRJSzN5Bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gDpHfip2T/L91h6tb7NdL5ei7ZV2PMe3nc/a4cBYAkGjskQMB02eQsOGM2bcO+o7k GvqbCdJ7JlN3HAqcU2gjPUmgCvkQ1ZConCaO+aXqO88fSonasLcAIliaayZrQlu/JM N7sNYHDkvycj5KWhMzydN3r6htRltyJE71NvVn7E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbfEOLrE (ORCPT ); Wed, 15 May 2019 07:47:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:35640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731430AbfEOLY7 (ORCPT ); Wed, 15 May 2019 07:24:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 827CF20843; Wed, 15 May 2019 11:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919499; bh=OU8sNd8F8lxRYqqaTc9NVhkBLTtyB79LwudRJSzN5Bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1fiSQe9XxqzqOlfvtr3RivmfjDEDp9ZLiAGoGU79FXrHZFrMJfqRg53ASN6Eoe9K6 DvnFmDJy+KXmfPx/w+VS9QzXobgOFrFz1DlUphaLalrSTSUoKKNenjt+y3918Dq39x 4iMfF+SZPUTKFZgdfx8qHbDKu2Xvn3mdc1Z7zr7Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Deseyn , Paolo Abeni , Marcelo Ricardo Leitner , "David S. Miller" Subject: [PATCH 4.19 099/113] selinux: do not report error on connect(AF_UNSPEC) Date: Wed, 15 May 2019 12:56:30 +0200 Message-Id: <20190515090701.140481639@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090652.640988966@linuxfoundation.org> References: <20190515090652.640988966@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Paolo Abeni [ Upstream commit c7e0d6cca86581092cbbf2cd868b3601495554cf ] calling connect(AF_UNSPEC) on an already connected TCP socket is an established way to disconnect() such socket. After commit 68741a8adab9 ("selinux: Fix ltp test connect-syscall failure") it no longer works and, in the above scenario connect() fails with EAFNOSUPPORT. Fix the above falling back to the generic/old code when the address family is not AF_INET{4,6}, but leave the SCTP code path untouched, as it has specific constraints. Fixes: 68741a8adab9 ("selinux: Fix ltp test connect-syscall failure") Reported-by: Tom Deseyn Signed-off-by: Paolo Abeni Reviewed-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- security/selinux/hooks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4800,7 +4800,7 @@ static int selinux_socket_connect_helper struct lsm_network_audit net = {0,}; struct sockaddr_in *addr4 = NULL; struct sockaddr_in6 *addr6 = NULL; - unsigned short snum; + unsigned short snum = 0; u32 sid, perm; /* sctp_connectx(3) calls via selinux_sctp_bind_connect() @@ -4823,12 +4823,12 @@ static int selinux_socket_connect_helper break; default: /* Note that SCTP services expect -EINVAL, whereas - * others expect -EAFNOSUPPORT. + * others must handle this at the protocol level: + * connect(AF_UNSPEC) on a connected socket is + * a documented way disconnect the socket. */ if (sksec->sclass == SECCLASS_SCTP_SOCKET) return -EINVAL; - else - return -EAFNOSUPPORT; } err = sel_netport_sid(sk->sk_protocol, snum, &sid);