All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v24 6/8] mptcp: remove CB offset field
Date: Mon, 09 Nov 2026 21:18:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-205661@kernel.org> (raw)
In-Reply-To: <8b30d5f811cfc37189badb3f7c86f565059063e4.1794215614.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mptcp: sk_forward_alloc corruption in mptcp_init_skb() on paged
  pull
- [Medium] mptcp: rewound map_seq in mptcp_init_skb() exposes
  unvalidated prefix
--

commit 53ea4c3d9a0507effa8276bb08b2e103414e8c2d
Author: Paolo Abeni <pabeni@redhat.com>

mptcp: remove CB offset field

This commit replaces the per-skb MPTCP_SKB_CB(skb)->offset field with an
msk-level copied_seq counter and handles already-consumed skb prefixes in
mptcp_init_skb().

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index ce0f9c2e6fd1a..30933dd9f0b1d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c

[ ... ]

> @@ -375,6 +375,11 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
>  				 *  |     skb1    |
>  				 * continue traversing
>  				 */
> +			} else if (MPTCP_SKB_CB(skb)->flags &
> +				   MPTCP_SKB_CB_F_OFFSET) {
> +				/* skb covers skb1 but has an unvalidated
> +				 * prefix; keep skb1, continue traversing.
> +				 */
>  			} else {
>  				/* skb's seq == skb1's seq and skb covers skb1.
>  				 * Replace skb1 with skb.
> @@ -415,25 +420,54 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
>  	skb_set_owner_r(skb, sk);
>  }
>  
> -static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
> -			   int copy_len)
> +static bool mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset)
>  {
>  	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
>  	bool has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
>  
> +	/* Detect mapping boundary: skb spans multiple mappings */
> +	if (unlikely(offset > 0 &&
> +		     before(TCP_SKB_CB(skb)->seq - subflow->ssn_offset,
> +			    subflow->map_subflow_seq))) {
> +		if (offset >= skb->len) {
> +			sk_eat_skb(ssk, skb);
> +			return false;
> +		}
> +
> +		if (offset > skb_headlen(skb)) {
> +			skb_orphan(skb);
> +			if (!pskb_pull(skb, offset)) {
> +				sk_eat_skb(ssk, skb);
> +				return false;
> +			}
> +			skb->truesize = SKB_TRUESIZE(skb_end_offset(skb)) +
> +					skb->data_len;
> +			skb_set_owner_r(skb, ssk);
> +		} else {
> +			if (!skb_pull(skb, offset)) {
> +				sk_eat_skb(ssk, skb);
> +				return false;
> +			}
> +		}
> +		offset = 0;
> +	}

[Severity: High]
Does orphaning and re-charging skb here corrupt ssk->sk_forward_alloc and
subflow->lent_mem_frag?

skb_orphan(skb) invokes sock_rfree() -> sk_mem_uncharge(ssk, orig_truesize),
which calls sk_mem_reclaim() and returns whole pages from
ssk->sk_forward_alloc to tcp_memory_allocated.  skb_set_owner_r(skb, ssk)
then calls sk_mem_charge(ssk, skb->truesize) without sk_rmem_schedule(),
subtracting the new truesize from ssk->sk_forward_alloc without allocating
backing pages, and altering skb->truesize breaks the PAGE_SIZE alignment
that mptcp_subflow_lend_fwdmem() and __mptcp_close_ssk() rely on.  When the
subflow closes, ssk->sk_forward_alloc is left negative (triggering
WARN_ON_ONCE(sk->sk_forward_alloc) in inet_sock_destruct()) while msk
reclaims the transferred pages a second time.

Note that pskb_expand_head() only adjusts skb->truesize when !skb->sk or
skb->destructor == sock_edemux, so calling pskb_pull() directly while skb is
still owned by ssk avoids changing skb->truesize or touching
ssk->sk_forward_alloc.

> +
>  	/* the skb map_seq accounts for the skb offset:
>  	 * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
>  	 * value
>  	 */
> -	MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow);
> -	MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
> -	MPTCP_SKB_CB(skb)->offset = offset;
> +	MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow) -
> +				     offset;
> +	MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + skb->len;
> +	MPTCP_SKB_CB(skb)->flags = offset ? MPTCP_SKB_CB_F_OFFSET : 0;

[Severity: Medium]
Can rewinding MPTCP_SKB_CB(skb)->map_seq by offset expose the unvalidated
prefix to the receive and out-of-order queues?

When an incoming subflow segment overlaps tp->copied_seq within the current
DSS mapping, validate_data_csum() starts at tp->copied_seq +
subflow->map_csum_len and does not validate the first offset bytes of skb.
Because mptcp_init_skb() rewinds map_seq to include that prefix and only
records a single bit in MPTCP_SKB_CB_F_OFFSET:

In mptcp_data_queue_ofo(), if the already-validated range in
msk->out_of_order_queue spans more than one skb (for example skb1a covering
[1000, 1050) and skb1b covering [1050, 1100)) and a segment arrives with
mapped_dsn 1100 and offset 100, traversal skips replacing skb1a via the
MPTCP_SKB_CB_F_OFFSET check, moves right to skb1b, sees seq (1000) <
skb1b->map_seq (1050), inserts skb to the left of skb1b, and then drops the
checksum-validated skb1b in merge_right, replacing [1050, 1100) with skb's
unvalidated prefix.  Similarly, mptcp_prune_ofo_queue() compares the rewound
in_skb->map_seq against the validated ooo_last_skb and can prune it, and in
__mptcp_move_skb(), if the earlier segment that advanced tp->copied_seq was
dropped at the msk level due to backlog or rmem limits before advancing
msk->ack_seq, the unvalidated prefix is accepted as in-sequence data.

Pulling offset bytes in mptcp_init_skb() whenever offset > 0 (not only
across mapping boundaries) would strip the unvalidated prefix before map_seq
is set.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794215614.git.tanggeliang@kylinos.cn?part=6

  reply	other threads:[~2026-11-09 21:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  9:24 [PATCH mptcp-next v24 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-11-09  9:24 ` [PATCH mptcp-net v24 1/8] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
2026-11-10 23:32   ` netdev-bot+sashiko
2026-11-09  9:24 ` [PATCH mptcp-next v24 2/8] selftests: mptcp: connect: check TFO SIOCINQ overflow Geliang Tang
2026-11-10 23:32   ` netdev-bot+sashiko
2026-11-09  9:24 ` [PATCH mptcp-net v24 3/8] mptcp: fix fallback dummy mapping anchor Geliang Tang
2026-11-09  9:24 ` [PATCH mptcp-next v24 4/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
2026-11-09  9:24 ` [PATCH mptcp-next v24 5/8] mptcp: drop the cant_coalesce CB field Geliang Tang
2026-11-09  9:24 ` [PATCH mptcp-next v24 6/8] mptcp: remove CB offset field Geliang Tang
2026-11-09 21:18   ` sashiko-bot [this message]
2026-11-10 23:32   ` netdev-bot+sashiko
2026-11-09  9:24 ` [PATCH mptcp-next v24 7/8] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-11-10 23:32   ` netdev-bot+sashiko
2026-11-09  9:24 ` [PATCH mptcp-next v24 8/8] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-11-10 23:32   ` netdev-bot+sashiko
2026-11-09 11:21 ` [PATCH mptcp-next v24 0/8] Reduce the differences between TCP and MPTCP for TLS usage MPTCP CI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-205661@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.