From nobody Sun May 24 22:35:48 2026 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CE3D3ED3B8 for ; Wed, 20 May 2026 18:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779300463; cv=none; b=NkkS/6hafXEh9CDiNBD3az52cG3yCcE6u1l+uBYgmBGMOjGYYEfUkd5mgCNsE8XLau1j9dND1e8TwkP7zsx5vGegsvG9LuvZpuKD3FP1RXKi9Ya1wbNImxu6GKgu9LGcbH/u7Mr+AkRrfqFnP+CJdw+5EbZlUP2BpmDROLV365s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779300463; c=relaxed/simple; bh=xfNlFdn1cqV9kYZZDjV/Uwxd3csiryoiiiDv+XVg55o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tGOiVOS/E7Hk/MaW1QbUmOgq2Ck7sWN9utLQKgdqfmVDV+olVzwB8NWfLRIE8LC5ZuQ0vK5Q3pKP19n5LD1xDhXHSUZyA0X8g0GFgEymY0W7DZWFgZUSCoZG2n+lcEQiDzQL+L8dqBBoZiRtBiD3lFuAynYHUQMwbwQu3XyM8xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hWeVJZTe; arc=none smtp.client-ip=74.125.82.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hWeVJZTe" Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-2f7020a928eso7509007eec.1 for ; Wed, 20 May 2026 11:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779300461; x=1779905261; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nklZPvrJ0WfKoc1xZCOc0oOhjU6AGmqWwTNyTfjgmsQ=; b=hWeVJZTeigJzObalTM7AUZy47yEbDptJfL2UhHrLO2c4T4AvgZKuRNypI/yP7gPZRx QeUdPsyIxX8BugFuQ5mYBFH5pITc2XDpBQz5RpJt93hdvARv+mWeBdlNb/ZtTmdJs2Ms jCXJZ+d03cMS/w18h/pWaGORbfxKePv1hPiOatN+6VrI4vOWFnrFEsb3eIjMoMOeYD8t yxEFGWIKaimXpbpD8Ttd7uXRJ/JLwuFECJsDFUEC7TPRInFjAKsc+P65FiVMBzGpEq6U XcWfYnazumOI0ppIJGUMpSGFoACsF3qYKgeifp+l6NNj9ejdsPoxJ4xleQa5iRkY0R3k 6KvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779300461; x=1779905261; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nklZPvrJ0WfKoc1xZCOc0oOhjU6AGmqWwTNyTfjgmsQ=; b=bpCyLgeZp0XQXrzdP1uqzU+A5PdgPspryt7mcR31jDl2Qkr3sS/mxE/VNkUxC9NMWC +ylewjSbdlJDugrblh9X9LTGKqKxvfTXSYpsXTynwy80ZtLIdtyVISFLwnpkQg+1VoBo Oraf5ICDNida+FRVcI00uk5Tl6SwqWjkhgnN9Rdfgt/Ww9fnPi/geD1mlPHoi668ckVu ZP8rEaKCliHwJ9DKaiFNawDQb+q59MyVaK8xowsfhvgtDfmUhxAgKAhsGLUR1P5k7B7v TAdwzp69y2y1UA13lL2DmqsU/CPxo9nnBIWMCwwFdWSt8KonbdsoUyLodvn8PHMWZA+s fwUg== X-Gm-Message-State: AOJu0YwVI58PhI/WKGm/upTpAW1TaXcLKiLOPFuV4e6DMOfJJoUVgqXG IZCxQWKhlPt9R1wgIUXbgNpoKPPH/qwUn2qpRzjqHzUUfQB1Uiaa1UId X-Gm-Gg: Acq92OFWvW0GUjXc9Z5blnzvIILO1J7Pmbc3hQ5LfHjpFME/4ci0V6J0030NIT7/ehe 3il2I0ILoLwHNXQxD+0NpEHoloSEpe7YO02EGILI3SiVQmsPUz/eli4YkUzTRdYVM1aKSV4/Oke cBpjnr8O5086tiCxgF/EuIV8T8TES+uj7O9oTM5Yj1MdqV13sBoQLOkl5JBjjpQti1VP0uq5qpE 1Z/b/tqF3XZAtNhsuykHtOsNpaKkL6lLamjOUKt4a5YhZ+0itmuBQiIZRhtUXvRvrZ45X5BvFem dW/xYojLJE75ZEvosMUEBQcBOHbuEachbZ3EWbyzUj8sm5Dz0LP0XQ5BSaqY82cqYbzdL91Hqfu wfLgQOdIyidAnPhHKfV/Bpm67IAXx4wpjZAiAlh6Up3CPGNd8c86AHiXhJbE6dTl49UptmwiKaI YAlAS+0AGICQFEQzS6UNI4dlyEXAJply1kRJnJrA== X-Received: by 2002:a05:7300:a505:b0:2e2:4979:eb5 with SMTP id 5a478bee46e88-303982b2f85mr11180375eec.10.1779300460601; Wed, 20 May 2026 11:07:40 -0700 (PDT) Received: from localhost.localdomain ([148.135.103.3]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30294500726sm18183954eec.10.2026.05.20.11.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 11:07:40 -0700 (PDT) From: Shaomin Chen To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Steffen Klassert , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Christian Hopps , stable@vger.kernel.org Subject: [PATCH net] xfrm: iptfs: reset runtime state when cloning SAs Date: Thu, 21 May 2026 02:07:23 +0800 Message-ID: <20260520180723.965339-1-eeesssooo020@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" iptfs_clone_state() clones the IPTFS mode data with kmemdup(). This copies runtime objects which must not be shared with the original SA, including the embedded sk_buff_head, hrtimers, spinlock, and in-flight reassembly/reorder state. If xfrm_state_migrate() fails after clone_state() but before the later init_state() call has reinitialized those fields, the cloned state can be destroyed by xfrm_state_gc_task() with list and timer state copied from the original SA. With queued packets this lets the clone splice and free skbs owned by the original IPTFS queue, leading to use-after-free and double-free reports in iptfs_destroy_state() and skb release paths. Reinitialize the clone's runtime state before publishing it through x->mode_data. Because clone_state() now publishes a destroyable mode_data object before init_state(), take the mode callback module reference there. Avoid taking it again from __iptfs_init_state() for the same object. Fixes: 0e4fbf013fa5 ("xfrm: iptfs: add user packet (tunnel ingress) handlin= g") Cc: stable@vger.kernel.org Signed-off-by: Shaomin Chen --- net/xfrm/xfrm_iptfs.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 97bc979e55ba..6c6bbc040517 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -2650,7 +2650,8 @@ static void __iptfs_init_state(struct xfrm_state *x, x->props.enc_hdr_len =3D sizeof(struct ip_iptfs_hdr); =20 /* Always keep a module reference when x->mode_data is set */ - __module_get(x->mode_cbs->owner); + if (x->mode_data !=3D xtfs) + __module_get(x->mode_cbs->owner); =20 x->mode_data =3D xtfs; xtfs->x =3D x; @@ -2658,22 +2659,39 @@ static void __iptfs_init_state(struct xfrm_state *x, =20 static int iptfs_clone_state(struct xfrm_state *x, struct xfrm_state *orig) { + struct skb_wseq *w_saved =3D NULL; struct xfrm_iptfs_data *xtfs; =20 xtfs =3D kmemdup(orig->mode_data, sizeof(*xtfs), GFP_KERNEL); if (!xtfs) return -ENOMEM; =20 - xtfs->ra_newskb =3D NULL; if (xtfs->cfg.reorder_win_size) { - xtfs->w_saved =3D kzalloc_objs(*xtfs->w_saved, - xtfs->cfg.reorder_win_size); - if (!xtfs->w_saved) { + w_saved =3D kzalloc_objs(*w_saved, xtfs->cfg.reorder_win_size); + if (!w_saved) { kfree_sensitive(xtfs); return -ENOMEM; } } + xtfs->w_saved =3D w_saved; + + __skb_queue_head_init(&xtfs->queue); + xtfs->queue_size =3D 0; + hrtimer_setup(&xtfs->iptfs_timer, iptfs_delay_timer, CLOCK_MONOTONIC, + IPTFS_HRTIMER_MODE); + + spin_lock_init(&xtfs->drop_lock); + hrtimer_setup(&xtfs->drop_timer, iptfs_drop_timer, CLOCK_MONOTONIC, + IPTFS_HRTIMER_MODE); =20 + xtfs->w_seq_set =3D false; + xtfs->w_wantseq =3D 0; + xtfs->w_savedlen =3D 0; + xtfs->ra_newskb =3D NULL; + xtfs->ra_wantseq =3D 0; + xtfs->ra_runtlen =3D 0; + + __module_get(x->mode_cbs->owner); x->mode_data =3D xtfs; xtfs->x =3D x; =20 --=20 2.47.3