Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3293576rwa; Tue, 23 Aug 2022 02:09:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4E/Fu6O67XcMPHjtkhZF3wYr08s5K++Ra9l+4JrHDZ3+Qh4eo6xogSdaLKGccglHzMG/O9 X-Received: by 2002:aa7:d802:0:b0:445:e618:fae8 with SMTP id v2-20020aa7d802000000b00445e618fae8mr2870104edq.182.1661245746747; Tue, 23 Aug 2022 02:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245746; cv=none; d=google.com; s=arc-20160816; b=IYOIMVdHhqs8odSWhRd0Y0PT4RPn5Tk77AGgWgSBMoHrLRwa3yIHHeNCTkLVh3iQxu yAtLepJibFOBKYJJSOZRUOwonNmjPo75W85evxYLHo83ROWzziHkdm0vILlhRuGS+91N wE7C1mF7qwlwVPMvPs1u7+AjEq1lJnQC5ddSE9jreTWsyuOT+QjNlF9bfFFfeMg/jIOY KrVrFXmo5L7pwy9GU6ilYvN+i3pvbEL3zsGOcXZxt1eqy6Sknb7xIxfhP1cC5IiVtPtY X1H6VPtbATVsH77YdHWGQEIOd7udpfk8bYenXYnULSJOi54MxEP6cM4MVWgEDOqx6Gkf 9EMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/wv7DhViBcU9wcdHZ/oZCqfBxJ6/iyFiFnWPbeZ1SyA=; b=QqHYVKODuovVM+dh4dadCHXBKgxa8s01bf1tETWLIJjuia4poludRMuXdqfizTQvwq MCBkPfqWJGm75Dxu/K00jqDpn//LiSC9aWx37jUt86omqi3LzgkUZQPOHNVyWNbX47S0 V82nAC8jL3X1xpto91ACXjBSTLV57lKvMIoUq3mq+lpF5PwY7PzPQsdP88bg/7gKs2v+ KAoXjhALviNyGLQKcb7LXvzztTGqsueQe+LXmSJqtjzR15RGfaHSKiKPFajOJxRGdhwn Tz5N5eazKkX7Dy9p5E6cX6wVlkxRH+4qGwJ7KxRYiq0wg8SAlfnpQMS16tVfG9LisgmO j/mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gMKtjQ+D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m22-20020a17090679d600b00732fd03ab1fsi10696158ejo.492.2022.08.23.02.08.37; Tue, 23 Aug 2022 02:09:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gMKtjQ+D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240811AbiHWI5w (ORCPT + 99 others); Tue, 23 Aug 2022 04:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241489AbiHWI52 (ORCPT ); Tue, 23 Aug 2022 04:57:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E5F10550; Tue, 23 Aug 2022 01:25:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3E6ACB81C4C; Tue, 23 Aug 2022 08:19:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FAECC433D7; Tue, 23 Aug 2022 08:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242773; bh=keD4PPoxYhzM6PyquEBtEeIYUAl7WnMlu51eH/WuM1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gMKtjQ+D6b4XdxhkALtiUV6BCN9Z0PsrIvA2ljJaANLY+lj/uhuRqjUlkgv2BqE81 QnVqbsSIIGZGvXo5KJfzxfGYiYPpftv25H76KiXB2scEm34QINac4vVSPQZLXFqf90 bj+oyJHMkbuAhiRbH45oq1ET3eCYBxVH958Lm9Pw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 5.19 194/365] netfilter: nf_ct_ftp: prefer skb_linearize Date: Tue, 23 Aug 2022 10:01:35 +0200 Message-Id: <20220823080126.336978835@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Westphal commit c783a29c7e5934eabac2b760571489ad83bf4fd1 upstream. This uses a pseudo-linearization scheme with a 64k global buffer, but BIG TCP arrival means IPv6 TCP stack can generate skbs that exceed this size. Use skb_linearize. It should be possible to rewrite this to properly deal with segmented skbs (i.e., only do small chunk-wise accesses), but this is going to be a lot more intrusive than this because every helper function needs to get the sk_buff instead of a pointer to a raw data buffer. In practice, provided we're really looking at FTP control channel packets, there should never be a case where we deal with huge packets. Fixes: 7c4e983c4f3c ("net: allow gso_max_size to exceed 65536") Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536") Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_ftp.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c index a414274338cf..0d9332e9cf71 100644 --- a/net/netfilter/nf_conntrack_ftp.c +++ b/net/netfilter/nf_conntrack_ftp.c @@ -34,11 +34,6 @@ MODULE_DESCRIPTION("ftp connection tracking helper"); MODULE_ALIAS("ip_conntrack_ftp"); MODULE_ALIAS_NFCT_HELPER(HELPER_NAME); -/* This is slow, but it's simple. --RR */ -static char *ftp_buffer; - -static DEFINE_SPINLOCK(nf_ftp_lock); - #define MAX_PORTS 8 static u_int16_t ports[MAX_PORTS]; static unsigned int ports_c; @@ -398,6 +393,9 @@ static int help(struct sk_buff *skb, return NF_ACCEPT; } + if (unlikely(skb_linearize(skb))) + return NF_DROP; + th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph); if (th == NULL) return NF_ACCEPT; @@ -411,12 +409,8 @@ static int help(struct sk_buff *skb, } datalen = skb->len - dataoff; - spin_lock_bh(&nf_ftp_lock); - fb_ptr = skb_header_pointer(skb, dataoff, datalen, ftp_buffer); - if (!fb_ptr) { - spin_unlock_bh(&nf_ftp_lock); - return NF_ACCEPT; - } + spin_lock_bh(&ct->lock); + fb_ptr = skb->data + dataoff; ends_in_nl = (fb_ptr[datalen - 1] == '\n'); seq = ntohl(th->seq) + datalen; @@ -544,7 +538,7 @@ static int help(struct sk_buff *skb, if (ends_in_nl) update_nl_seq(ct, seq, ct_ftp_info, dir, skb); out: - spin_unlock_bh(&nf_ftp_lock); + spin_unlock_bh(&ct->lock); return ret; } @@ -571,7 +565,6 @@ static const struct nf_conntrack_expect_policy ftp_exp_policy = { static void __exit nf_conntrack_ftp_fini(void) { nf_conntrack_helpers_unregister(ftp, ports_c * 2); - kfree(ftp_buffer); } static int __init nf_conntrack_ftp_init(void) @@ -580,10 +573,6 @@ static int __init nf_conntrack_ftp_init(void) NF_CT_HELPER_BUILD_BUG_ON(sizeof(struct nf_ct_ftp_master)); - ftp_buffer = kmalloc(65536, GFP_KERNEL); - if (!ftp_buffer) - return -ENOMEM; - if (ports_c == 0) ports[ports_c++] = FTP_PORT; @@ -603,7 +592,6 @@ static int __init nf_conntrack_ftp_init(void) ret = nf_conntrack_helpers_register(ftp, ports_c * 2); if (ret < 0) { pr_err("failed to register helpers\n"); - kfree(ftp_buffer); return ret; } -- 2.37.2