Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp462843yba; Wed, 15 May 2019 04:33:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyL36PhAsFD+NnswyyrmWUwPgOUETWX5UzdGgdp/FT7KJcKAxQXXt53XxXZrfUEmhRK3Haw X-Received: by 2002:a63:36c6:: with SMTP id d189mr29712675pga.8.1557919984479; Wed, 15 May 2019 04:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557919984; cv=none; d=google.com; s=arc-20160816; b=EnNUyjEhWLpSlwFmRC+/LJJeO582k+n4X3ab3Sc/R3MFII1EXyedT5RWFDHZDpvris ngrE1kpPjmXL9xmTl2s1Sozq17eLguRNeFblPIuIUKbWO0a47jtQdF/KxRhkdAGidfwq kRDg95oURrUWbK3Jmx+fZtECxjRJRW9pE5ndgZUwj+kLSvKLOx44MX1W6rSoYOJXV5oP 0ksp22q1Ef2hFHEoAi2qVHFP0LIr3u9mgSPiMFDfutN6aD/wBvCHepWI3kL7S7RTR5uL WYYSYV0u5SYzgpX4HqrkUtrg8QkGVFfeFOwNHcquqqUCdufqeBgHbUwSeigVs4so0dAN eo7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oGcv5LSvl9OwSQGwgyUmf02dL4w1w3r6Zwie0i3UDUQ=; b=yxbfKw5jayOdUuDxEf4flIktRss2Kj8p7khRnOlcD08gtB9uMpeO5Abh/CmPmKEZ92 fUy7q4j6kRs/Vc4MQ6r37qaiiQAXaPMIFZTRIypy+HJ4Awf/y4xn6SxH7y3RHW/0ZKIk bb53AOPPn+sAyU1YtqkaJUACkiUoBfZISGWMspu0/CLjFYcI9bA2aYCqXc4AMzvdT/qj /teIKOO1+h6iu87hntp1h395wql2xp7+TgXp/Ex4fRNPX2oQQcdyfktCEGKB1ZIRW4qZ 0TkV/U9FrbP0VQab327l6gxb8wGJMDEFITmkUx1yiiZiwwii4CI+7fg7/4aUPG2oIYvI Igqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qqIezXfY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9si1527812pgs.364.2019.05.15.04.32.49; Wed, 15 May 2019 04:33:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qqIezXfY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732809AbfEOLa4 (ORCPT + 99 others); Wed, 15 May 2019 07:30:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:42494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732802AbfEOLaw (ORCPT ); Wed, 15 May 2019 07:30:52 -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 C9DE62084A; Wed, 15 May 2019 11:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919852; bh=BCvMcltUnVEXK2iVLgfaCW7IIQVbEsVCdADXsrdqLdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qqIezXfYlIh+yujt9UCVb9ZUJIw+ZSxCydxnwOoKHFnDGFtaEuh8zjoWUrQ9tXURr kAvOfXQvj9cUFbiMpS7jYwFbzlu7y+vN7eEQmCwnbj4zWwsJWXWyG8m0xf7NCHzHrr xtTytUS4R6+4SoAeteCIC8738/4QplLzfKvnmoxg= 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 5.0 116/137] selinux: do not report error on connect(AF_UNSPEC) Date: Wed, 15 May 2019 12:56:37 +0200 Message-Id: <20190515090702.058105887@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -4586,7 +4586,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() @@ -4609,12 +4609,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);