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=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no 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 4001CC433DF for ; Tue, 2 Jun 2020 08:55:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1418320734 for ; Tue, 2 Jun 2020 08:55:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="IfTL60Fv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbgFBIzR (ORCPT ); Tue, 2 Jun 2020 04:55:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726217AbgFBIzP (ORCPT ); Tue, 2 Jun 2020 04:55:15 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E257C061A0E for ; Tue, 2 Jun 2020 01:55:15 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id mb16so11968748ejb.4 for ; Tue, 02 Jun 2020 01:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=UpZeVaraeAQCVNTZxXpOffz+FSPS8pHdNGnocyS2mhk=; b=IfTL60FvMGXj/A7fWRprxLo4myJSe/7osNvWnXdiUhVLmyrNXubAGMwIkVO9CPVnJa C0J6bji0V7H6sHXSlwvcr/L8YjnMrYhoZGXOqHzOOEWJfBsn/9BNRPCD255Y/YPiij1V vkPqMp6+ldS0xbEku1m5tfZw40rDl+vFsUCt4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=UpZeVaraeAQCVNTZxXpOffz+FSPS8pHdNGnocyS2mhk=; b=QQnaJqn7uzT8Bh9hxasbFOuqeMNBxLe+THiikQuo6I8bZcIH6NcxJwBqb5fQCILGXo d16BfXS/V9d88drncJpmGvTmycHBqvqIVX5S3Eo8vEG46XF7La6MQWAjzbTpTnQw8oWT +7LjebBvA+GIVehoifHKzrfIiWtjfcaBNn3H0z5UYoSzQ8mL0Ud6hzCEk2RXj63T5h6T 1FvE8CTYSKDoyBr+lnz3xszP5g+eLmNIzpvgqZJmWqp8tcao5SLE3zim1SlgXVXqFTMc 5xIE/ezfQVx9c8U5b6QAaUn+ck0grlqUvNklPZgJvllHMTBnuvd9ZVDbirZkS/R+LAfC 9/iw== X-Gm-Message-State: AOAM531or801bn6CmZU9bvOJvNxkvOB1325bFky5e6WMhGOE6XYiQKO1 5nkL8UfwMUwN6Iachs3znxhWmA== X-Google-Smtp-Source: ABdhPJwJqxgwVu93QJg4CxBwG5J1Q0TEJ2Y32gJowtg7cF18HlBLAu2TrQXYuGRlXg4kMh8XqgxwhQ== X-Received: by 2002:a17:906:934d:: with SMTP id p13mr23219841ejw.414.1591088113536; Tue, 02 Jun 2020 01:55:13 -0700 (PDT) Received: from cloudflare.com ([2a02:a310:c262:aa00:b35e:8938:2c2a:ba8b]) by smtp.gmail.com with ESMTPSA id la5sm1347388ejb.94.2020.06.02.01.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 01:55:12 -0700 (PDT) References: <159079336010.5745.8538518572099799848.stgit@john-Precision-5820-Tower> <159079361946.5745.605854335665044485.stgit@john-Precision-5820-Tower> <20200601165716.5a6fa76a@toad> <5ed51cae71d0d_3f612ade269e05b46e@john-XPS-13-9370.notmuch> <5ed523a8b7749_54cc2acde13425b85b@john-XPS-13-9370.notmuch> User-agent: mu4e 1.1.0; emacs 26.3 From: Jakub Sitnicki To: John Fastabend Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, alexei.starovoitov@gmail.com, daniel@iogearbox.net Subject: Re: [bpf-next PATCH 2/3] bpf: fix running sk_skb program types with ktls In-reply-to: <5ed523a8b7749_54cc2acde13425b85b@john-XPS-13-9370.notmuch> Date: Tue, 02 Jun 2020 10:55:11 +0200 Message-ID: <87img93l00.fsf@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Mon, Jun 01, 2020 at 05:50 PM CEST, John Fastabend wrote: > John Fastabend wrote: >> Jakub Sitnicki wrote: >> > On Fri, 29 May 2020 16:06:59 -0700 >> > John Fastabend wrote: >> > >> > > KTLS uses a stream parser to collect TLS messages and send them to >> > > the upper layer tls receive handler. This ensures the tls receiver >> > > has a full TLS header to parse when it is run. However, when a >> > > socket has BPF_SK_SKB_STREAM_VERDICT program attached before KTLS >> > > is enabled we end up with two stream parsers running on the same >> > > socket. >> > > >> > > The result is both try to run on the same socket. First the KTLS >> > > stream parser runs and calls read_sock() which will tcp_read_sock >> > > which in turn calls tcp_rcv_skb(). This dequeues the skb from the >> > > sk_receive_queue. When this is done KTLS code then data_ready() >> > > callback which because we stacked KTLS on top of the bpf stream >> > > verdict program has been replaced with sk_psock_start_strp(). This >> > > will in turn kick the stream parser again and eventually do the >> > > same thing KTLS did above calling into tcp_rcv_skb() and dequeuing >> > > a skb from the sk_receive_queue. >> > > >> > > At this point the data stream is broke. Part of the stream was >> > > handled by the KTLS side some other bytes may have been handled >> > > by the BPF side. Generally this results in either missing data >> > > or more likely a "Bad Message" complaint from the kTLS receive >> > > handler as the BPF program steals some bytes meant to be in a >> > > TLS header and/or the TLS header length is no longer correct. >> > > >> > > We've already broke the idealized model where we can stack ULPs >> > > in any order with generic callbacks on the TX side to handle this. >> > > So in this patch we do the same thing but for RX side. We add >> > > a sk_psock_strp_enabled() helper so TLS can learn a BPF verdict >> > > program is running and add a tls_sw_has_ctx_rx() helper so BPF >> > > side can learn there is a TLS ULP on the socket. >> > > >> > > Then on BPF side we omit calling our stream parser to avoid >> > > breaking the data stream for the KTLS receiver. Then on the >> > > KTLS side we call BPF_SK_SKB_STREAM_VERDICT once the KTLS >> > > receiver is done with the packet but before it posts the >> > > msg to userspace. This gives us symmetry between the TX and >> > > RX halfs and IMO makes it usable again. On the TX side we >> > > process packets in this order BPF -> TLS -> TCP and on >> > > the receive side in the reverse order TCP -> TLS -> BPF. >> > > >> > > Discovered while testing OpenSSL 3.0 Alpha2.0 release. >> > > >> > > Fixes: d829e9c4112b5 ("tls: convert to generic sk_msg interface") >> > > Signed-off-by: John Fastabend >> > > --- > > [...] > >> > > +static void sk_psock_tls_verdict_apply(struct sk_psock *psock, >> > > + struct sk_buff *skb, int verdict) >> > > +{ >> > > + switch (verdict) { >> > > + case __SK_REDIRECT: >> > > + sk_psock_skb_redirect(psock, skb); >> > > + break; >> > > + case __SK_PASS: >> > > + case __SK_DROP: >> > >> > The two cases above need a "fallthrough;", right? >> >> Correct otherwise will get the "fallthrough" patch shortly after this >> lands. Thanks I'll add it. >> > > hmm actually I don't think we need 'fallthrough;' here when the > case doesn't have statements, > > switch (a) { > case 1: > case 2: > default: > break; > } > > seems OK to me. I don't have a preference though so feel free to > correct me. I misunderstood guidance in [0]. You're right, it seems too verbose to annotate cases without statements. Didn't mean to nit-pick :-) [0] https://www.kernel.org/doc/html/latest/process/deprecated.html#implicit-switch-case-fall-through