Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3787308ybi; Mon, 29 Jul 2019 12:36:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgY4RBGrPHlROuscuOrbZ+Prj1rIJOgyBsytoqAb0mKqyR08tHsuqT4Pd5itDPTEd0vF/L X-Received: by 2002:a65:528d:: with SMTP id y13mr17021943pgp.120.1564429019586; Mon, 29 Jul 2019 12:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429019; cv=none; d=google.com; s=arc-20160816; b=huDMvToB9+zDMnZ+xLCyfCHfLESZNpVmPkBjfv+AYZXICBbV7/0R9OWf6l4Qu+6aDe +xg36RdFRvtCh3F812quE7vT0puRTZ/ihk914Lgw3zSWqIpVKXPi9uTv6O8Ie5ribeol hL/Ouve78EJoWl7LdvGy2Av/ArmzeDLEacXqpU0LQewSWDJvY2GDQL2NZCtW1mlBSK6l +U4A4avksPa5zLx7KKR9LzVrwqDcn8tTpUsMs0kd5OSDp7YjkrYqB/fmuTdjeOZqfXVR 9XhGv0dyue9giyo2PnrjcSI8bpqvsYL5mi6KV9iWxuLZXb5JKCIPikLnv/sUAFQ+XiDP zUrQ== 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=ru34Rudj9nku/VmYMSETz1cf+pxJq8qzHirGDiAsBDY=; b=eSxti1rHDbiVfYbp65BsQa+hRQ1fQOWziJIB1YLKVpjdzonM8gsBm7QN1ebUil9mbf ufrGDfOrbUFqgxkIoNYfCr92jifd1rrcjBZgq7Ia+anX8e76ta75FTbViNXZPrIS8g3r kG5UA5d5gFbFMDn09UYq4jFC5MHQsluTeOWPubB5PGrPxsfXwVNE7OxevdYh4IKkE6dh q/mlxknybMT+Y5M5LGkYFXqABWuTZbBbsynkUOYHVMMb1nn2sXOHhuPL/Qt+Gv+DAbYk FlioSZA/ubRtyzjgku6VXhwhqXitwDv0Tt4IGpMrhv/7EBlTLclVnQN+BWFfhYX/5RzO kSSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rMHhqusw; 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 bc7si27138832plb.55.2019.07.29.12.36.45; Mon, 29 Jul 2019 12:36:59 -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=rMHhqusw; 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 S2387885AbfG2Tdw (ORCPT + 99 others); Mon, 29 Jul 2019 15:33:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:48158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729402AbfG2Tdu (ORCPT ); Mon, 29 Jul 2019 15:33:50 -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 990542171F; Mon, 29 Jul 2019 19:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428829; bh=XhTA8PoUkzEYG4NqiODIrmkO834GvK3lKmU38uHhakc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMHhqusw1EhMgrKWtihkdkRNarwcGT8p3eGNNYe//vtbl7mJAG7qePfEvqTWOZ3tX nAPxtV9Q56ZK8pmgO2yA7jNsxnGjh0MUL5E6GAbrBqZUgwuaWCOHqf8xxCPwT6ReTX YZA6zIuArRul3gGlG4AVhIRdImu/KfFUzc4gsABE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Lawrence Brakmo , Neal Cardwell , "David S. Miller" Subject: [PATCH 4.14 200/293] tcp: fix tcp_set_congestion_control() use from bpf hook Date: Mon, 29 Jul 2019 21:21:31 +0200 Message-Id: <20190729190839.809665460@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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: Eric Dumazet [ Upstream commit 8d650cdedaabb33e85e9b7c517c0c71fcecc1de9 ] Neal reported incorrect use of ns_capable() from bpf hook. bpf_setsockopt(...TCP_CONGESTION...) -> tcp_set_congestion_control() -> ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN) -> ns_capable_common() -> current_cred() -> rcu_dereference_protected(current->cred, 1) Accessing 'current' in bpf context makes no sense, since packets are processed from softirq context. As Neal stated : The capability check in tcp_set_congestion_control() was written assuming a system call context, and then was reused from a BPF call site. The fix is to add a new parameter to tcp_set_congestion_control(), so that the ns_capable() call is only performed under the right context. Fixes: 91b5b21c7c16 ("bpf: Add support for changing congestion control") Signed-off-by: Eric Dumazet Cc: Lawrence Brakmo Reported-by: Neal Cardwell Acked-by: Neal Cardwell Acked-by: Lawrence Brakmo Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/tcp.h | 3 ++- net/core/filter.c | 3 ++- net/ipv4/tcp.c | 4 +++- net/ipv4/tcp_cong.c | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1043,7 +1043,8 @@ void tcp_get_default_congestion_control( void tcp_get_available_congestion_control(char *buf, size_t len); void tcp_get_allowed_congestion_control(char *buf, size_t len); int tcp_set_allowed_congestion_control(char *allowed); -int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, bool reinit); +int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, + bool reinit, bool cap_net_admin); u32 tcp_slow_start(struct tcp_sock *tp, u32 acked); void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked); --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3122,7 +3122,8 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_so strncpy(name, optval, min_t(long, optlen, TCP_CA_NAME_MAX-1)); name[TCP_CA_NAME_MAX-1] = 0; - ret = tcp_set_congestion_control(sk, name, false, reinit); + ret = tcp_set_congestion_control(sk, name, false, + reinit, true); } else { struct tcp_sock *tp = tcp_sk(sk); --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2500,7 +2500,9 @@ static int do_tcp_setsockopt(struct sock name[val] = 0; lock_sock(sk); - err = tcp_set_congestion_control(sk, name, true, true); + err = tcp_set_congestion_control(sk, name, true, true, + ns_capable(sock_net(sk)->user_ns, + CAP_NET_ADMIN)); release_sock(sk); return err; } --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -338,7 +338,8 @@ out: * tcp_reinit_congestion_control (if the current congestion control was * already initialized. */ -int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, bool reinit) +int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, + bool reinit, bool cap_net_admin) { struct inet_connection_sock *icsk = inet_csk(sk); const struct tcp_congestion_ops *ca; @@ -372,8 +373,7 @@ int tcp_set_congestion_control(struct so } else { err = -EBUSY; } - } else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || - ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))) { + } else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin)) { err = -EPERM; } else if (!try_module_get(ca->owner)) { err = -EBUSY;