Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4821506ybl; Wed, 22 Jan 2020 05:23:51 -0800 (PST) X-Google-Smtp-Source: APXvYqw6c7gM1ZVkK1kR3kTmjNrHeKaNoTuxB5l5JMbUqX/LmZAnge9bs0cklSMRN5g9HpZdbIPU X-Received: by 2002:a05:6808:c:: with SMTP id u12mr6882525oic.107.1579699431566; Wed, 22 Jan 2020 05:23:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699431; cv=none; d=google.com; s=arc-20160816; b=bTeaTs9P+OBqC9NKdoiwVIJv9/coozJ+pbcG0Q84tebncbtl3Mtr9KTZijJ1Z8tgs+ FtZp96rhDhNpyKk84pMubc52j7p9CK9FOOp2y4V9MmSP7COf5NaUvskyf49++9p+RRFu UmZr+um+batLB7c04+8r71UudYgdHC3jOKJV1T0MirZ0EFqubdTPtRVfXcPnRVZw+mZE fvsq0WO019bdV7KutSjQ1oPPFiUdt3Qq97djDj3k4EYCAqFYUFMzXNggY3cKxnfbD99D jllsSj/N8nZh2mguL4+s0dvA5puC1h+awD1WaIP7tKOFZkijDfcTmXNkgLCOASXZhkPU 0h9A== 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=0G7tFZsjqFPQTN0nEiadquNNevGKrfyE8YltPjA2fRI=; b=hF30J72JdbaHruw3S+jYqZzrsYF4oiH38ikk4MydbIlGyL4UvY8BSafQTENf+9DMuk dmXOcNeJb6lyBeNO21FLAmEi6pz/VdNkQqqhz/mLGU5tzJWP14pkfMtbtTmGYYVWr1b5 DQCScD917cWv/X7IO25k2A8pYxEAKLoWYYXdoJZ71lYJtCOHpzEPcWQTeyHhxeIbtSlI eg5Q4blPQw4WCMhxVkwDUcNVa0Te8gnolO2viX9DBifBWA0PpK81v12YjFBO+RD364Yw GVRNMWKLtARktiMKxd646sZ70A0re/6CkGIA1zR7tzCezFIYWga6Iv7c7oUKgcoNquPH VKHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WIh1oDvX; 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 r4si23938909otq.188.2020.01.22.05.23.39; Wed, 22 Jan 2020 05:23:51 -0800 (PST) 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=WIh1oDvX; 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 S1730591AbgAVNWb (ORCPT + 99 others); Wed, 22 Jan 2020 08:22:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:40144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725827AbgAVNW3 (ORCPT ); Wed, 22 Jan 2020 08:22:29 -0500 Received: from localhost (unknown [84.241.205.26]) (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 3C4E62468C; Wed, 22 Jan 2020 13:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699348; bh=AZh0/pB0q2KopdriTAOIAUemGtq0gw/o3+IlVV507gY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WIh1oDvXENvYrBxG76Ga+z3qHERYu9PXPffYrT03s29qxFaIQkIAK5FIyvJTB1207 tlY3p8DFf7e9beD6LF3S8XZq3r9tgMGMwks6voBc3048KAx1vIJn5jOZPtLT8ozQlN 0vzjLp3AIIG/WxFHjOQRwALaDxc+g85onBODxtm8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Fastabend , Daniel Borkmann , Jakub Sitnicki , Jonathan Lemon Subject: [PATCH 5.4 110/222] bpf: Sockmap/tls, push write_space updates through ulp updates Date: Wed, 22 Jan 2020 10:28:16 +0100 Message-Id: <20200122092841.611847883@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@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: John Fastabend commit 33bfe20dd7117dd81fd896a53f743a233e1ad64f upstream. When sockmap sock with TLS enabled is removed we cleanup bpf/psock state and call tcp_update_ulp() to push updates to TLS ULP on top. However, we don't push the write_space callback up and instead simply overwrite the op with the psock stored previous op. This may or may not be correct so to ensure we don't overwrite the TLS write space hook pass this field to the ULP and have it fixup the ctx. This completes a previous fix that pushed the ops through to the ULP but at the time missed doing this for write_space, presumably because write_space TLS hook was added around the same time. Fixes: 95fa145479fbc ("bpf: sockmap/tls, close can race with map free") Signed-off-by: John Fastabend Signed-off-by: Daniel Borkmann Reviewed-by: Jakub Sitnicki Acked-by: Jonathan Lemon Cc: stable@vger.kernel.org Link: https://lore.kernel.org/bpf/20200111061206.8028-4-john.fastabend@gmail.com Signed-off-by: Greg Kroah-Hartman --- include/linux/skmsg.h | 12 ++++++++---- include/net/tcp.h | 6 ++++-- net/ipv4/tcp_ulp.c | 6 ++++-- net/tls/tls_main.c | 10 +++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) --- a/include/linux/skmsg.h +++ b/include/linux/skmsg.h @@ -355,17 +355,21 @@ static inline void sk_psock_restore_prot struct sk_psock *psock) { sk->sk_prot->unhash = psock->saved_unhash; - sk->sk_write_space = psock->saved_write_space; if (psock->sk_proto) { struct inet_connection_sock *icsk = inet_csk(sk); bool has_ulp = !!icsk->icsk_ulp_data; - if (has_ulp) - tcp_update_ulp(sk, psock->sk_proto); - else + if (has_ulp) { + tcp_update_ulp(sk, psock->sk_proto, + psock->saved_write_space); + } else { sk->sk_prot = psock->sk_proto; + sk->sk_write_space = psock->saved_write_space; + } psock->sk_proto = NULL; + } else { + sk->sk_write_space = psock->saved_write_space; } } --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2132,7 +2132,8 @@ struct tcp_ulp_ops { /* initialize ulp */ int (*init)(struct sock *sk); /* update ulp */ - void (*update)(struct sock *sk, struct proto *p); + void (*update)(struct sock *sk, struct proto *p, + void (*write_space)(struct sock *sk)); /* cleanup ulp */ void (*release)(struct sock *sk); /* diagnostic */ @@ -2147,7 +2148,8 @@ void tcp_unregister_ulp(struct tcp_ulp_o int tcp_set_ulp(struct sock *sk, const char *name); void tcp_get_available_ulp(char *buf, size_t len); void tcp_cleanup_ulp(struct sock *sk); -void tcp_update_ulp(struct sock *sk, struct proto *p); +void tcp_update_ulp(struct sock *sk, struct proto *p, + void (*write_space)(struct sock *sk)); #define MODULE_ALIAS_TCP_ULP(name) \ __MODULE_INFO(alias, alias_userspace, name); \ --- a/net/ipv4/tcp_ulp.c +++ b/net/ipv4/tcp_ulp.c @@ -96,17 +96,19 @@ void tcp_get_available_ulp(char *buf, si rcu_read_unlock(); } -void tcp_update_ulp(struct sock *sk, struct proto *proto) +void tcp_update_ulp(struct sock *sk, struct proto *proto, + void (*write_space)(struct sock *sk)) { struct inet_connection_sock *icsk = inet_csk(sk); if (!icsk->icsk_ulp_ops) { + sk->sk_write_space = write_space; sk->sk_prot = proto; return; } if (icsk->icsk_ulp_ops->update) - icsk->icsk_ulp_ops->update(sk, proto); + icsk->icsk_ulp_ops->update(sk, proto, write_space); } void tcp_cleanup_ulp(struct sock *sk) --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -798,15 +798,19 @@ out: return rc; } -static void tls_update(struct sock *sk, struct proto *p) +static void tls_update(struct sock *sk, struct proto *p, + void (*write_space)(struct sock *sk)) { struct tls_context *ctx; ctx = tls_get_ctx(sk); - if (likely(ctx)) + if (likely(ctx)) { + ctx->sk_write_space = write_space; ctx->sk_proto = p; - else + } else { sk->sk_prot = p; + sk->sk_write_space = write_space; + } } static int tls_get_info(const struct sock *sk, struct sk_buff *skb)