From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795927820; b=aqOPLCRjeft+vq0YqiaugYIRrR4q3E+H8v86mz7jnuHvHvZEIUWl0oVMdUj6vb3Ba66k 8qvapL39+Anv7Udl2d7jTaqwUynceOlbo0jzBBQmievFET3aEaamx6li3wcNMiHZeOs/p ow+awtdXJP9Djn5yx48DgEAC6VSwTLlE6cdPHy/QP8Dw8yAXYpa573cbxxRwjTy0G4xlo Y3JBvDlsayKRglD2sZ0gifRHiYpHKdzQ1YaZMt0BJGEveil8dvHLGhi1Uby4fEglQm8ss XvIHYgCQJ8IYnR6OXlUxnCfCkGPVqndupvbRZjBwf+/BMhVGgyV94I1NW2EBP11yigg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795927820; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: X-Relaying-Domain:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=/I7QzYaCpA385xuTDbtpL/bnc6KWg6F4TZr4h0xzsHs=; b=l+YBMcEiJCsbuY48D/ykqQEprrkzA1VADJ+q0yUcJjOHvJHbM0jG5ClRBP92f0pXrhIN SlwA1OdzkCqPefNESItjkZSyYGzF9hTh6qzuXzk313CMZPiWBt02njXzkaWm95iZzLS1L ah2+w4fDOzWuJdsyX/sYSQJOIiWphDbxGMIyQGoPrwxMsvU02xUrHXWVfk6KXTUrkoXR+ jwE4Y1Fa6Ix+06Z2YP2rTiyEvaGhYOV4kM92KS53QdDE/2rauoIcV5gBW63dB/M0wXz/y LLRHuaNU2f89NUZWT6rLZpixCo3ou4eghf+O44w6S8+XyBgNeHIwfkvqqvYiE+XX+9w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=andrii.net; spf=pass smtp.mailfrom=andrii.net; dkim=pass header.d=andrii.net header.i=@andrii.net header.a=rsa-sha256 header.s=gmail-2025 header.b="Yu/k6ASs"; arc=none smtp.remote-ip=74.125.82.100 Received: from mail-dl1-f100.google.com (mail-dl1-f100.google.com [74.125.82.100]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23B8D606A6AD for ; Sun, 29 Nov 2026 04:50:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23B8D606A6AD Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=andrii.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=andrii.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=andrii.net header.i=@andrii.net header.a=rsa-sha256 header.s=gmail-2025 header.b=Yu/k6ASs Received: by mail-dl1-f100.google.com with SMTP id a92af1059eb24-15ea896ddc8so15348464c88.0 for ; Sat, 28 Nov 2026 20:50:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrii.net; s=gmail-2025; t=1795927819; x=1796532619; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/I7QzYaCpA385xuTDbtpL/bnc6KWg6F4TZr4h0xzsHs=; b=Yu/k6ASs82VbJs8rKoMo4JqbA5aC3STAAOXqPQB48dPheio6qUxh2Onb2r5RhQ8hED zcxONhQLBBZPNef5cr8cWsbKhU7EM3BQGNxhNhwD3wzGVw1hjIq49+oker66F53F0Ao0 jy/m2rs5ftHH9yGGvH0b7cxcSjwqODK/F3SHOhQGvQ29HCcjfgg6jIFNy3AiDU1B80TV E1mu8TGnPbaZvuQyMkutLCoiBSniqEHr6+c7ZijHuzdK25tV3HJX9SlJOnKSbj4jWSZ8 5fga17/IdlgrKcSNG4wLYi1PJ1TA5c0VclIiyGd814G48tFK65aADDPexsDE3n1hezfK zQWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795927819; x=1796532619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=/I7QzYaCpA385xuTDbtpL/bnc6KWg6F4TZr4h0xzsHs=; b=rLlsQzSWUtLDYpFOVM9XWjXfREuhqDXkvnbxima2UJsLuRgt0IGquWofi16iQI5FSa 1jGd8Km/oHNH9aY0EcJISrCFYwWuw11TPgNglAnZF+pEzeVly6hP2fmVQAr51h7MR/II wUeWmDN97Rt0b+HZysn1cRJrAclFJfHF7u1ZM2G3r+t1h29o2amCb9PN36t+/Mwi6sbN bYH8sp7jXycc8NpRAMamOnYPpoXrr88MXY4ado7R/h8LncXp5Euq2OYiJ0+f5yYc/UMV 24L8KkU8LSe0a6qAqp/gCHFykWH/x/Rot4FCHuQbOY0AzCuvBtfh9qJE5y0xwxwIUw2e 1QgA== X-Forwarded-Encrypted: i=1; AL+hErEg3S41NG3jF945Tr1Yla8jr3ue4uJ00oFFfGuoZ8XBsQYrblgI7YicumlGM6Vd60osH+S4qwho3dH9ZYQ=@vger.kernel.org X-Gm-Message-State: APuU4Z9UXtmV6ZEAfZawSTHuLx/eKudxr1sjD/Eu/7MxfCpRu9UwHDmT jTvxbZu1aMsMTYQMLDxEfqzRZIbWAFIxaXMXPOeH55CaYcQis/GOATQGvVxu5zzqluo8rMMkXwa i5f3yvr4LdSn+92g1KsmamZmGwT1HzKKuxPFM0KlwGiM6TNi8w84C X-Gm-Gg: AZFdTZfYTrKpLGEC0AK9OI+YxPGfpBNdV19RcF8QEMi5Ff0cyNM7Nd2mwolKwFltuvx 9iRpZEmkrj2W7T4UrYAREMRK6SfVYzjejI49qO4ixBqGk+ZxwYW/hPYy50IUJWLUoNixSkq3C7/ TezGANik5kNchrrOyYDsmm+yx5b43hsMnz1DEVm/mZ2gtrU9tlmrfv2XyKroT0eZLnPyzaqdxHS IMQmfZE3UeJ6/scvLLKt07LNFZdKpE4s1OJumX/kecGZWbGKKfmbbMDmj7bhkFFLHU3BifATyO1 /DvrgEjVSZDXju86fKk3wkJtGbXN2u50VG8wX71QqXaUvk6f8kDppOEl4g06lb9H2omAOvBXirN jL+eJz7xdi8sR4asKxPA3fwpW95U= X-Received: by 2002:a05:7300:1c1b:b0:386:9d31:2d18 with SMTP id 5a478bee46e88-3869d313208mr22607965eec.0.1795927819364; Sat, 28 Nov 2026 20:50:19 -0800 (PST) Received: from andrii.ai (mac.hestia.andrii.net. [2602:f337:ed:4865:7374:6961:204d:6163]) by smtp-relay.gmail.com with ESMTPS id 5a478bee46e88-38566dd1e87sm4856399eec.11.2026.11.28.20.50.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Nov 2026 20:50:19 -0800 (PST) X-Relaying-Domain: andrii.net From: Andrii Tereshchenko To: Steffen Klassert , Herbert Xu , "David S. Miller" Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Willem de Bruijn , Christian Hopps , netdev@vger.kernel.org, ipsec@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size Date: Sat, 28 Nov 2026 21:50:11 -0700 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: <8cfaaaca-0668-485f-bc87-f9fde6c4b25d@mid.andrii.net> References: <8cfaaaca-0668-485f-bc87-f9fde6c4b25d@mid.andrii.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit XFRMA_IPTFS_PKT_SIZE is the size of the outer packet, but iptfs_user_init() turns it into a data budget by taking away only header_len, not ESP's padding, trailer and ICV. Full outer packets are therefore larger than pkt_size, 1020 bytes for 1000 with AES-GCM, and on a path that pkt_size was set to fit, for example one that filters ICMP, they are dropped without a trace. The budget is also kept when the SA is migrated to another family or encapsulation, which changes header_len: moving it to IPv6 adds another 20 bytes. Drop payload_mtu, convert pkt_size with __iptfs_get_inner_mtu() each time it is used, and refuse a pkt_size that leaves no room for data. Made with an AI coding assistant, reviewed by the submitter. Fixes: 4b3faf610cc6 ("xfrm: iptfs: add new iptfs xfrm mode impl") Cc: stable@vger.kernel.org Signed-off-by: Andrii Tereshchenko --- Found by an AI code review agent. Validated in KVM guests on unmodified ipsec master, without kernel changes: with AES-GCM and a pkt_size of 1000, none of 200 forwarded datagrams crossed a router whose next link has an MTU of 1000 and which sends no ICMP errors, and a pkt_size of 50 was accepted. Tested: with this patch all 200 cross and a pkt_size of 50 is refused. The migration case was tested with a KUnit case of my own, not posted. Not tested: hardware ESP offload, the existing net selftests. net/xfrm/xfrm_iptfs.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index bd4d445428d6c..49b761d0a6be1 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -133,7 +133,6 @@ struct skb_wseq { * @init_delay_ns: nanoseconds to wait to send initial IPTFS packet. * @iptfs_timer: output timer. * @iptfs_settime: time the output timer was set. - * @payload_mtu: max payload size. * @w_seq_set: true after first seq received. * @w_wantseq: waiting for this seq number as next to process (in order). * @w_saved: the saved buf array (reorder window). @@ -158,7 +157,6 @@ struct xfrm_iptfs_data { u64 init_delay_ns; /* nanoseconds */ struct hrtimer iptfs_timer; /* output timer */ time64_t iptfs_settime; /* time timer was set */ - u32 payload_mtu; /* max payload size */ /* Tunnel input reordering */ bool w_seq_set; /* true after first seq received */ @@ -1804,11 +1802,13 @@ static int iptfs_get_cur_pmtu(struct xfrm_state *x, struct xfrm_iptfs_data *xtfs struct sk_buff *skb) { struct xfrm_dst *xdst = (struct xfrm_dst *)skb_dst(skb); - u32 payload_mtu = xtfs->payload_mtu; u32 pmtu = __iptfs_get_inner_mtu(x, xdst->child_mtu_cached); - if (payload_mtu && payload_mtu < pmtu) - pmtu = payload_mtu; + /* Converted here rather than once, as migration can change + * header_len. + */ + if (xtfs->cfg.pkt_size) + pmtu = min(pmtu, __iptfs_get_inner_mtu(x, xtfs->cfg.pkt_size)); return pmtu; } @@ -2574,13 +2574,12 @@ static int iptfs_user_init(struct net *net, struct xfrm_state *x, } if (attrs[XFRMA_IPTFS_PKT_SIZE]) { xc->pkt_size = nla_get_u32(attrs[XFRMA_IPTFS_PKT_SIZE]); - if (!xc->pkt_size) { - xtfs->payload_mtu = 0; - } else if (xc->pkt_size > x->props.header_len) { - xtfs->payload_mtu = xc->pkt_size - x->props.header_len; - } else { + /* pkt_size is the whole outer packet, ESP padding, trailer + * and ICV included; iptfs_get_cur_pmtu() converts it. + */ + if (xc->pkt_size && !__iptfs_get_inner_mtu(x, xc->pkt_size)) { NL_SET_ERR_MSG(extack, - "Packet size must be 0 or greater than IPTFS/ESP header length"); + "Packet size must be 0 or greater than IPTFS/ESP overhead"); return -EINVAL; } } -- 2.53.0