Commit 179f185
net: skbuff: propagate shared-frag marker through frag-transfer helpers
commit 48f6a53 upstream.
Two frag-transfer helpers (__pskb_copy_fclone() and skb_shift()) fail
to propagate the SKBFL_SHARED_FRAG bit in skb_shinfo()->flags when
moving frags from source to destination. __pskb_copy_fclone() defers
the rest of the shinfo metadata to skb_copy_header() after copying
frag descriptors, but that helper only carries over gso_{size,segs,
type} and never touches skb_shinfo()->flags; skb_shift() moves frag
descriptors directly and leaves flags untouched. As a result, the
destination skb keeps a reference to the same externally-owned or
page-cache-backed pages while reporting skb_has_shared_frag() as
false.
The mismatch is harmful in any in-place writer that uses
skb_has_shared_frag() to decide whether shared pages must be detoured
through skb_cow_data(). ESP input is one such writer (esp4.c,
esp6.c), and a single nft 'dup to <local>' rule -- or any other
nf_dup_ipv4() / xt_TEE caller -- is enough to land a pskb_copy()'d
skb in esp_input() with the marker stripped, letting an unprivileged
user write into the page cache of a root-owned read-only file via
authencesn-ESN stray writes.
Set SKBFL_SHARED_FRAG on the destination whenever frag descriptors
were actually moved from the source. skb_copy() and skb_copy_expand()
share skb_copy_header() too but linearize all paged data into freshly
allocated head storage and emerge with nr_frags == 0, so
skb_has_shared_frag() returns false on its own; they need no change.
The same omission exists in skb_gro_receive() and skb_gro_receive_list().
The former moves the incoming skb's frag descriptors into the
accumulator's last sub-skb via two paths (a direct frag-move loop and
the head_frag + memcpy path); the latter chains the incoming skb whole
onto p's frag_list. Downstream skb_segment() reads only
skb_shinfo(p)->flags, and skb_segment_list() reuses each sub-skb's
shinfo as the nskb -- both p and lp must carry the marker.
The same omission also exists in tcp_clone_payload(), which builds an
MTU probe skb by moving frag descriptors from skbs on sk_write_queue
into a freshly allocated nskb. The helper falls into the same family
and warrants the same fix for consistency; no TCP TX-side in-place
writer is currently known to reach a user page through this gap, but
a future consumer depending on the marker would regress silently.
The same omission exists in skb_segment(): the per-iteration flag
merge takes only head_skb's flag, and the inner switch that rebinds
frag_skb to list_skb on head_skb-frags exhaustion does not fold the
new frag_skb's flag into nskb. Fold frag_skb's flag at both sites
so segments drawing frags from frag_list members carry the marker.
Fixes: cef401d ("net: fix possible wrong checksum generation")
Fixes: f4c50a4 ("xfrm: esp: avoid in-place decrypt on shared skb frags")
Suggested-by: Sabrina Dubroca <sd@queasysnail.net>
Suggested-by: Sultan Alsawaf <sultan@kerneltoast.com>
Suggested-by: Ben Hutchings <ben@decadent.org.uk>
Suggested-by: Lin Ma <malin89@huawei.com>
Suggested-by: Jingguo Tan <tanjingguo@huawei.com>
Suggested-by: Aaron Esau <aaron1esau@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Tested-by: Rajat Gupta <rajat.gupta@oss.qualcomm.com>
Link: https://patch.msgid.link/ageeJfJHwgzmKXbh@v4bel
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
[bwh: Backported to 5.15:
- skb_gro_receive() and skb_gro_receive_list() are in skbuff.c here
- Drop change to tcp_clone_payload(), which does not exist here
- Adjust context in skb_shift()
]
Signed-off-by: Ben Hutchings <benh@debian.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent 2f2b160 commit 179f185
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1661 | 1661 | | |
1662 | 1662 | | |
1663 | 1663 | | |
| 1664 | + | |
1664 | 1665 | | |
1665 | 1666 | | |
1666 | 1667 | | |
| |||
3650 | 3651 | | |
3651 | 3652 | | |
3652 | 3653 | | |
| 3654 | + | |
| 3655 | + | |
3653 | 3656 | | |
3654 | 3657 | | |
3655 | 3658 | | |
| |||
4017 | 4020 | | |
4018 | 4021 | | |
4019 | 4022 | | |
| 4023 | + | |
| 4024 | + | |
4020 | 4025 | | |
4021 | 4026 | | |
4022 | 4027 | | |
| |||
4251 | 4256 | | |
4252 | 4257 | | |
4253 | 4258 | | |
4254 | | - | |
| 4259 | + | |
| 4260 | + | |
4255 | 4261 | | |
4256 | 4262 | | |
4257 | 4263 | | |
| |||
4268 | 4274 | | |
4269 | 4275 | | |
4270 | 4276 | | |
| 4277 | + | |
| 4278 | + | |
| 4279 | + | |
4271 | 4280 | | |
4272 | 4281 | | |
4273 | 4282 | | |
| |||
4490 | 4499 | | |
4491 | 4500 | | |
4492 | 4501 | | |
| 4502 | + | |
4493 | 4503 | | |
4494 | 4504 | | |
4495 | 4505 | | |
4496 | 4506 | | |
| 4507 | + | |
4497 | 4508 | | |
4498 | 4509 | | |
4499 | 4510 | | |
| |||
0 commit comments