From patchwork Thu Oct 11 00:45:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Borkmann X-Patchwork-Id: 982149 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=iogearbox.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vshz4QJSz9sB7 for ; Thu, 11 Oct 2018 11:46:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726066AbeJKIKu (ORCPT ); Thu, 11 Oct 2018 04:10:50 -0400 Received: from www62.your-server.de ([213.133.104.62]:50844 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbeJKIKt (ORCPT ); Thu, 11 Oct 2018 04:10:49 -0400 Received: from [62.203.87.61] (helo=localhost) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1gAP78-0002jA-NO; Thu, 11 Oct 2018 02:46:06 +0200 From: Daniel Borkmann To: alexei.starovoitov@gmail.com Cc: john.fastabend@gmail.com, davejwatson@fb.com, netdev@vger.kernel.org, Daniel Borkmann Subject: [PATCH bpf-next 1/8] tcp, ulp: enforce sock_owned_by_me upon ulp init and cleanup Date: Thu, 11 Oct 2018 02:45:40 +0200 Message-Id: <20181011004547.16662-2-daniel@iogearbox.net> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181011004547.16662-1-daniel@iogearbox.net> References: <20181011004547.16662-1-daniel@iogearbox.net> X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.1/25025/Wed Oct 10 22:52:47 2018) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Whenever the ULP data on the socket is mangled, enforce that the caller has the socket lock held as otherwise things may race with initialization and cleanup callbacks from ulp ops as both would mangle internal socket state. Joint work with John. Signed-off-by: Daniel Borkmann Signed-off-by: John Fastabend --- net/ipv4/tcp_ulp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ipv4/tcp_ulp.c b/net/ipv4/tcp_ulp.c index a5995bb..34e9635 100644 --- a/net/ipv4/tcp_ulp.c +++ b/net/ipv4/tcp_ulp.c @@ -123,6 +123,8 @@ void tcp_cleanup_ulp(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); + sock_owned_by_me(sk); + if (!icsk->icsk_ulp_ops) return; @@ -140,6 +142,7 @@ int tcp_set_ulp(struct sock *sk, const char *name) const struct tcp_ulp_ops *ulp_ops; int err = 0; + sock_owned_by_me(sk); if (icsk->icsk_ulp_ops) return -EEXIST; @@ -168,6 +171,7 @@ int tcp_set_ulp_id(struct sock *sk, int ulp) const struct tcp_ulp_ops *ulp_ops; int err; + sock_owned_by_me(sk); if (icsk->icsk_ulp_ops) return -EEXIST;