From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.227 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795927818; b=BMBDFq7qpNOPt8cARh9TC/kmTaaIiQO2T7g4VIcKrpd+y6EpUdf/Fv3wA5dWg5n0b0jK 768CtRf1P6/iDXOAoVTEWGpJMpBiHAZVRQjzKYiSh0eQp1GKHg8Ros5ZqfbaTWvDwjK8W 4yQ5u+VGP04Ppz/g5TIynmaO8lh7h7hF9gg8q0XhAbM//e+gRz4cz0aXd6KpP3Z4AK5H9 mdwepZVe09lI/WXRndAbO7c3nB0Sb4GRuTscJHp56iAt19LzyUvfC56l2+a5hTAXmE4fs vYm77AHo1aa2YBka/Ygh+7ALnbu0HO+ckxocs7HsIhWHGysdpOYUMeuhiKhiIS139rw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795927818; 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=I5215P+Gba7qRsJu+wv/lZWPsjA7r4ucEG6tTypfqc8=; b=NwB5BJJWEUGkVzJI22AEiSsgOMMXio/9y67y82nPhpOKF1mSTSXeekLCRt9HLtzcc9ZF iYOh39/mCbHVqM0ipPo9T35dnYt6tlDn/zVPz2kc76L7dn7ZowkfIyPbiz3Ou+p1Mm0v3 J1Wi0bDV6jXed0ztTPoIRxLU/uF9h2B5ZjeZ5e9ygyMASGJhu0NCSpyAGuTNoQ/YTWFlN 96ARabrHuo8BgAdlrlAKJ2N6thl0xSnF+v7n4su1HyZhecdsvu685MJQ7UPZiib8zU7OY YFf6RzGXdX/Rh5jGWMR5LtPgfdpnHt1oSFe4ENYQKSCKmaFC1gNVYG3VwcOTUO1DHKQ== 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=JxBcw0KB; arc=none smtp.remote-ip=74.125.82.227 Received: from mail-dy1-f227.google.com (mail-dy1-f227.google.com [74.125.82.227]) (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 D135D606A32E for ; Sun, 29 Nov 2026 04:50:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D135D606A32E 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=JxBcw0KB Received: by mail-dy1-f227.google.com with SMTP id 5a478bee46e88-386ab9ab619so13544232eec.1 for ; Sat, 28 Nov 2026 20:50:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrii.net; s=gmail-2025; t=1795927817; x=1796532617; 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=I5215P+Gba7qRsJu+wv/lZWPsjA7r4ucEG6tTypfqc8=; b=JxBcw0KB+bFS2bjDWMKe9Q73/LyTJtxkQa/DBgyEHwaoEnK4+y337xcu05LmBEtSqF /u+rmTejTLD9eY90ksjxOZagzTm6GQ6oCXWeYqtvBhVreW6c13b7OSJ5WNFsZgIrdNNk 9BP+NqUwWHIvJTvpNalHysfncGT98DXpdIrhxZ9d09gJhDM+HV1MIDgag0EZlfLgl0Xc g+BaiC+iyRTHK8NyxorHJwGt3cYb5/GA8Go1JuK/n/MIwKM2OqziNHbWhVfJOS5fOWFe Oqc6cfgZYAV7OlSTFjdjJeajVtRQDmvhikt2fl66++iD2OP+MZXTwAVS1pTlZNvE++CN uhpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795927817; x=1796532617; 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=I5215P+Gba7qRsJu+wv/lZWPsjA7r4ucEG6tTypfqc8=; b=jLQErkLIbpeFJqm+vQB91SfeaUH7mI0D0+sk6lXJKiepsMMo3yMO7PeetP38BrBCIL W/5HfpMvFjJ+nTXqoWdLYC1bjIf9xiSy+/3cO7bfJzaIW+Ze10jyubKS5QEcGBi1SR5K jOyZwPwiI3ixa+LPz5FPROT8HI2fJigdqpzPK7rjaLBmyTh1nKmkS58FRufxPkA/getH ITBHtVO+GC9j2tSF0ofW98XEi8B6Qz/skqEqkpKh0LXlXgiS/wfDqYX5z7ZwJkcLcQkU +iSYYvRoBp51He6YmCjSuegHQf7Qpe9AoTSOHN7LI722n1aPNTn4xJNUfD71rvinaRVL RUeA== X-Forwarded-Encrypted: i=1; AL+hErE2TqSmCTAWfqiuzXnXbtCyzQhXcNP3bd1akpdbShxPpgX+1tp5txG2JqGSTTVQDQkjnlAEksPdgA0i+vU=@vger.kernel.org X-Gm-Message-State: APuU4Z8wwzinbNp3hJzFMm79ijRvEZ6N6RlFc6q3aHHHHUfNeK+RD9B3 tdmeuMCc4RsQwj82zsSSooGUEOXRrsQO8ZgfIJQgSctZqIMKV35cXxw1l++PVtUEyc87NFWBfTd jcJHNH6/0lx1tCI747UkCd+XO95LQhK9IrMlIX99j5cfEWNYOJAmU X-Gm-Gg: AZFdTZfkFGlGE3gYZdDJLy3KpNi3AcijF/jyP+NIm1BHObart9Pbd5+JenxANCUh8Df NQvkc8bm1yIXsVvBqdebGCmkKG2+nFwkU9ICQuRxHWjSs7TUU6wNsVwLVUq25ZkeG9jhj8o+9O3 2Wtsc+aXktCmyUCfnkZl4DWbkeeK9W/0dzN4AKlia4q+ius++lk2QLWIfukix8reLvrL/oo89xS mZKXRS2Y3SFp3+9Gd4cwvE7SdjJhGarqPhDh9Jk3YusKum7eDgnXd6tNnFvd9XNAvGcd/iZc/41 y56fcGk8PwwaYelKrBRbNW+1WChjqctuBx4/MlYbVySr2oWNg7njvVk0HXssPhBFAzHI9qbqREG I7BcnrDTIjkd3Qfx7xaJJIVN9TlA= X-Received: by 2002:a05:7300:1486:b0:383:6eb6:5730 with SMTP id 5a478bee46e88-38570e24c0fmr34906432eec.32.1795927817091; Sat, 28 Nov 2026 20:50:17 -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.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Nov 2026 20:50:17 -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 1/3] xfrm: iptfs: don't let the inner MTU wrap around Date: Sat, 28 Nov 2026 21:50:09 -0700 Message-ID: <10ceac4a-a93a-4ed9-9ea5-356c931664fe@mid.andrii.net> 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 __iptfs_get_inner_mtu() subtracts the SA's overhead from the outer MTU without checking that it fits. With an IPv4 MTU of 68 and AES-CBC-256 with HMAC-SHA512-256 (80 bytes of overhead) it wraps to almost 4G, IP-TFS builds oversized packets, and with ESP offload esp_xmit() panics on a fragment of one. An unprivileged user can set this up in a user namespace: skbuff: skb_under_panic: ... len:66 put:-14 ... dev:v0 esp_xmit+0x398/0x7c0 validate_xmit_xfrm+0x65d/0x710 Return 0 when no data fits and drop such packets; the get_inner_mtu callback then returns 1, as xfrm_state_mtu() does. 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 with ESP offload built in, without kernel changes or fault injection: an SA that uid 65534 set up in namespaces of its own over a 68-byte MTU panics the kernel on 2 of 2 boots. The reproducer is available to the maintainers on request. Tested: with this series the same setup survives 2 of 2 boots with panic_on_warn=1, and IP-TFS drops the packets (XfrmOutError). Not tested: an IPv6 outer header, hardware ESP offload, the existing net selftests. net/xfrm/xfrm_iptfs.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 0313a43aa8a97..c204f41a57f59 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -2215,10 +2215,11 @@ static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list) skb->protocol = x->outer_mode.family == AF_INET ? htons(ETH_P_IP) : htons(ETH_P_IPV6); - if (skb->len > mtu && xtfs->cfg.dont_frag) { + if (!mtu || (skb->len > mtu && xtfs->cfg.dont_frag)) { /* We handle this case before enqueueing so we are only * here b/c MTU changed after we enqueued before we - * dequeued, just drop these. + * dequeued, just drop these. An mtu of 0 means that the + * outer MTU cannot carry any data at all. */ XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTERROR); @@ -2490,17 +2491,25 @@ static int iptfs_prepare_output(struct xfrm_state *x, struct sk_buff *skb) * @x: xfrm state. * @outer_mtu: the outer mtu * - * Return: Correct MTU taking in to account the encap overhead. + * Return: Correct MTU taking in to account the encap overhead, or 0 if the + * outer MTU leaves no room for data. */ static u32 __iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu) { struct crypto_aead *aead; - u32 blksize; + u32 blksize, overhead, payload; aead = x->data; blksize = ALIGN(crypto_aead_blocksize(aead), 4); - return ((outer_mtu - x->props.header_len - crypto_aead_authsize(aead)) & - ~(blksize - 1)) - 2; + overhead = x->props.header_len + crypto_aead_authsize(aead); + if (outer_mtu <= overhead) + return 0; + + payload = (outer_mtu - overhead) & ~(blksize - 1); + if (payload <= 2) + return 0; + + return payload - 2; } /** @@ -2517,7 +2526,8 @@ static u32 iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu) /* If not dont-frag we have no MTU */ if (!xtfs->cfg.dont_frag) return x->outer_mode.family == AF_INET ? IP_MAX_MTU : IP6_MAX_MTU; - return __iptfs_get_inner_mtu(x, outer_mtu); + /* Like xfrm_state_mtu() for the other modes, never return 0 */ + return __iptfs_get_inner_mtu(x, outer_mtu) ?: 1; } /** -- 2.53.0