Skip to contentSkip to conversation

ppp: fix bsd_decompress() OOB read and ppp_decompress_frame() headroom check

PATCH In review Hui Peng 4 participants 4 messages Sep 19 – Sep 22

Subsystems (3)
lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH 1/1 ppp: fix bsd_decompress() OOB read and ppp_decompress_frame() headroom check

In ppp_decompress_frame(), skb->data - 2 is passed to the decompressor assuming at least 2 bytes of headroom exist for the PPP Address/Control fields, and the returned decompressed length is only checked for len < 0 before indexing ns->data[2..3] and calling skb_pull_rcsum(skb, 2).

Ensure 2 bytes of headroom via pskb_expand_head(skb, 2, 0, GFP_ATOMIC), reject decompressed frames shorter than PPP_HDRLEN (4 bytes), and check isize >= PPP_HDRLEN + BSD_OVHD in bsd_decompress() before reading the sequence number and header bytes.

Fixes 224cf5ad14c0 ("ppp: Move the PPP drivers")
Assisted-by LLM

---

drivers/net/ppp/bsd_comp.c +2 -0
index 63a6d251c746..03ee4ff4ec1b 100644
@@ -847,6 +847,8 @@ static int bsd_decompress (void *state, unsigned char *ibuf, int isize,
     int extra;
 
     db       = (struct bsd_db *) state;
+	if (isize < PPP_HDRLEN + BSD_OVHD)
+		return DECOMP_ERROR;
     max_ent  = db->max_ent;
     accm     = 0;
     bitno    = 32;		/* 1st valid bit in accm */
drivers/net/ppp/ppp_generic.c +3 -2
index 1a610a18893b..f7af328b7bf8 100644
@@ -2552,7 +2552,8 @@ ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
 	/* Until we fix all the decompressor's need to make sure
 	 * data portion is linear.
 	 */
-	if (!pskb_may_pull(skb, skb->len))
+	if (!pskb_may_pull(skb, skb->len) ||
+	    pskb_expand_head(skb, 2, 0, GFP_ATOMIC))
 		goto err;
 
 	if (proto == PPP_COMP) {
@@ -2576,7 +2577,7 @@ ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
 		/* the decompressor still expects the A/C bytes in the hdr */
 		len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
 				skb->len + 2, ns->data, obuff_size);
-		if (len < 0) {
+		if (len < PPP_HDRLEN) {
 			/* Pass the compressed frame to pppd as an
 			   error indication. */
 			if (len == DECOMP_FATALERROR)
#1 lore raw
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 3 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] ppp_decompress_frame() (drivers/net/ppp/ppp_generic.c:2555-2557) now calls pskb_expand_head(skb, 2, 0, GFP_ATOMIC) unconditionally on…
- [Medium] The commit message states that the decompressed length 'is only checked for len < 0 before indexing ns->data[2..3] and calling…
- [Medium] The patch hardens only one of the three in-tree implementers of struct compressor::decompress.
- [Medium] The new pskb_expand_head(skb, 2, 0, GFP_ATOMIC) in ppp_decompress_frame() (drivers/net/ppp/ppp_generic.c:2556) creates…

--

ppp: fix bsd_decompress() OOB read and ppp_decompress_frame() headroom check

This adds an isize floor check to bsd_decompress(), makes ppp_decompress_frame() call pskb_expand_head(skb, 2, 0, GFP_ATOMIC) to guarantee two bytes of headroom, and tightens the decompressed length check from len < 0 to len < PPP_HDRLEN.

No Link: tags were present in the commit header.

A few questions below.

Quoted 6 lines

ppp: fix bsd_decompress() OOB read and ppp_decompress_frame() headroom check

In ppp_decompress_frame(), skb->data - 2 is passed to the decompressor assuming at least 2 bytes of headroom exist for the PPP Address/Control fields, and the returned decompressed length is only checked for len < 0 before indexing ns->data[2..3] and calling skb_pull_rcsum(skb, 2).

[Severity: Medium]
Does this describe the code being patched? Neither an ns->data[2..3] access nor a skb_pull_rcsum(skb, 2) exists in ppp_decompress_frame(). The post-decompress sequence there is:

	consume_skb(skb);
	skb = ns;
	skb_put(skb, len);
	skb_pull(skb, 2);	/* pull off the A/C bytes */

	/* Don't call __ppp_decompress_proto() here, but instead rely on
	 * corresponding algo (mppe/bsd/deflate) to decompress it.
	 */

The only skb_pull_rcsum(skb, 2) in the file lives in the caller, ppp_receive_nonmp_frame(). The read that the new len < PPP_HDRLEN check actually protects looks like the two-byte

	proto = PPP_PROTO(skb);

in ppp_receive_nonmp_frame() after skb->len has been reduced to 1 by skb_put(3) + skb_pull(2), which the message does not mention. Could the message be updated to match the tree being patched, so that stable backport decisions can be checked against it?

drivers/net/ppp/bsd_comp.c static int bsd_decompress (void *state, unsigned char *ibuf, int isize, · line 852

Quoted 11 lines
drivers/net/ppp/bsd_comp.c +2 -0
index 63a6d251c746..03ee4ff4ec1b 100644
@@ -847,6 +847,8 @@ static int bsd_decompress (void *state, unsigned char *ibuf, int isize,
     int extra;
 
     db       = (struct bsd_db *) state;
+	if (isize < PPP_HDRLEN + BSD_OVHD)
+		return DECOMP_ERROR;
     max_ent  = db->max_ent;

[Severity: Medium]
Should this check instead live in the shared caller? There are three in-tree implementers of struct compressor::decompress, and they are all reached from the single dispatch point in ppp_decompress_frame():

	len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
			skb->len + 2, ns->data, obuff_size);

z_decompress() already validates isize before touching ibuf, and this patch adds the same for bsd_decompress(), but mppe_decompress() still reads ibuf[4] in a variable initializer that runs before its own length guard:

drivers/net/ppp/ppp_mppe.c:mppe_decompress() {
	int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;

	if (isize <= PPP_HDRLEN + MPPE_OVHD) {
		...
		return DECOMP_ERROR;
	}

with

#define MPPE_BITS(p) ((p)[4] & 0xf0)

The receive path only guarantees skb->len >= 2 (ppp_decompress_proto() does pskb_may_pull(skb, 2)), so a peer that has negotiated MPPE and sends a 2-byte PPP_COMP frame gives isize == 4 and makes ibuf[4] read one byte past the frame data. Does a single minimum-isize test at the dispatch point cover all three callbacks rather than leaving MPPE inconsistent?

Also, the indentation of the added lines uses tabs while the surrounding function uses the file's older 4-space style.

drivers/net/ppp/ppp_generic.c ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb) · line 2557

Quoted 12 lines
drivers/net/ppp/ppp_generic.c +2 -1
index 1a610a18893b..f7af328b7bf8 100644
@@ -2552,7 +2552,8 @@ ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
 	/* Until we fix all the decompressor's need to make sure
 	 * data portion is linear.
 	 */
-	if (!pskb_may_pull(skb, skb->len))
+	if (!pskb_may_pull(skb, skb->len) ||
+	    pskb_expand_head(skb, 2, 0, GFP_ATOMIC))
 		goto err;

[Severity: High]
Is the expansion meant to be unconditional? pskb_expand_head() has no "headroom is already sufficient" fast path:

net/core/skbuff.c:pskb_expand_head() {
	data = kmalloc_reserve(&size, gfp_mask, NUMA_NO_NODE, NULL);
	...
	memcpy(data + nhead, skb->head, skb_tail_pointer(skb) - skb->head);
	...
		skb_free_head(skb);
	...
	skb->truesize += size - osize;
}

nhead is additional headroom, so every received frame now takes a kmalloc + memcpy + free even though in-tree channels already reserve headroom, for example:

drivers/net/ppp/ppp_async.c:ppp_async_input() {
			if (buf[0] != PPP_ALLSTATIONS)
				skb_reserve(skb, 2 + (buf[0] & 1));

That skb_reserve() also arranges 4-byte payload alignment, which the unconditional reallocation discards. The call also sits before the proto == PPP_COMP test, so it runs for frames that never dereference skb->data - 2 at all (the else branch only calls ->incomp() when ppp->rcomp->incomp is non-NULL).

Separately, does a transient GFP_ATOMIC failure here have larger consequences than dropping one frame? The failure funnels into:

err:

	ppp->rstate |= SC_DC_ERROR;
	ppp_receive_error(ppp);

and the caller only enters the decompressor while that bit is clear:

drivers/net/ppp/ppp_generic.c:ppp_receive_nonmp_frame() {
	if (ppp->rc_state && (ppp->rstate & SC_DECOMP_RUN) &&
	    (ppp->rstate & (SC_DC_FERROR | SC_DC_ERROR)) == 0)
		skb = ppp_decompress_frame(ppp, skb);

SC_DC_ERROR is only cleared from ppp_ccp_peek() via

				ppp->rstate &= ~SC_DC_ERROR;

so one momentary atomic allocation failure appears to disable receive decompression for the whole link until a CCP Reset round trip. Would skb_cow_head(skb, 2), or an explicit

	if (skb_headroom(skb) < 2 && pskb_expand_head(skb, 2, 0, GFP_ATOMIC))

placed inside the branch that actually uses skb->data - 2, avoid both the per-packet copy and the new sticky failure mode?

[Severity: Medium]
Are the two new headroom bytes ever initialised? pskb_expand_head() allocates with kmalloc_reserve() (no __GFP_ZERO) and copies the old head to data + nhead, so data[0] and data[1] are never written. Afterwards skb->data == data + 2 + old_headroom, so when the incoming skb had less than 2 bytes of headroom, skb->data - 2 points into that uninitialised prefix, and that is exactly the case this change exists to handle.

Those bytes are then handed to the decompressor as the PPP Address/Control octets:

		/* the decompressor still expects the A/C bytes in the hdr */
		len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
				skb->len + 2, ns->data, obuff_size);

and in the uncompressed branch to:

		if (ppp->rcomp->incomp)
			ppp->rcomp->incomp(ppp->rc_state, skb->data - 2,
					   skb->len + 2);

bsd_decompress() consumes them and copies them into the output header:

    adrs  = PPP_ADDRESS (ibuf);
    ctrl  = PPP_CONTROL (ibuf);

z_decompress() and mppe_decompress() do the same. Headroom below 2 is reachable on the tty path: ppp_async_input() skips skb_reserve() when the frame starts with PPP_ALLSTATIONS, process_input_packet() pulls the two A/C bytes leaving headroom 2, and then a PFC-compressed protocol field consumes one more byte in __ppp_decompress_proto():

	if (ppp_skb_is_compressed_proto(skb))
		*(u8 *)skb_push(skb, 1) = 0x00;

Should the two bytes be filled with PPP_ALLSTATIONS/PPP_UI after the expansion, so the decompressors read the header the comment says they expect?

Quoted 9 lines
drivers/net/ppp/ppp_generic.c +1 -1
@@ -2576,7 +2577,7 @@ ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
 		/* the decompressor still expects the A/C bytes in the hdr */
 		len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
 				skb->len + 2, ns->data, obuff_size);
-		if (len < 0) {
+		if (len < PPP_HDRLEN) {
 			/* Pass the compressed frame to pppd as an
 			   error indication. */
 			if (len == DECOMP_FATALERROR)

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260919215233.3470411-1-benquike%40gmail.com
reviewer
#2 lore raw
Quoted 11 lines · On Sun, Sep 20, 2026 at 10:54:09PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 3 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

Quoted 8 lines

- [High] ppp_decompress_frame() (drivers/net/ppp/ppp_generic.c:2555-2557) now calls pskb_expand_head(skb, 2, 0, GFP_ATOMIC) unconditionally on…
- [Medium] The commit message states that the decompressed length 'is only checked for len < 0 before indexing ns->data[2..3] and calling…
- [Medium] The patch hardens only one of the three in-tree implementers of struct compressor::decompress.
- [Medium] The new pskb_expand_head(skb, 2, 0, GFP_ATOMIC) in ppp_decompress_frame() (drivers/net/ppp/ppp_generic.c:2556) creates…

Hi Hui,

There is an expectation that AI-generated reviews forwarded to the netdev ML are responded to. That can take a variety of forms including an email response that agrees with or refutes the review, or an updated version of the patch with an appropriate changelog.

The expectation is the patch author or submitter handles this. But in order to move things along, I did take a look over these and taken together it seems to me that these issues warrant a new revision of the patch.

Please keep in mind that distinct problems should be in separate patches, and related patches should be bundled together in a patchset.

Signature · 1 line
pw-bot: changes-requested
#3 lore raw
In reply to Hui Peng
Quoted 10 lines · Hui Peng

In ppp_decompress_frame(), skb->data - 2 is passed to the decompressor assuming at least 2 bytes of headroom exist for the PPP Address/Control fields, and the returned decompressed length is only checked for len < 0 before indexing ns->data[2..3] and calling skb_pull_rcsum(skb, 2).

Ensure 2 bytes of headroom via pskb_expand_head(skb, 2, 0, GFP_ATOMIC), reject decompressed frames shorter than PPP_HDRLEN (4 bytes), and check isize >= PPP_HDRLEN + BSD_OVHD in bsd_decompress() before reading the sequence number and header bytes.

Quoted 4 lines
Fixes 224cf5ad14c0 ("ppp: Move the PPP drivers")
Assisted-by LLM

---

You sent multiple independent patches, to multiple independent subsystems. The amount of these patches clearly suggest this was AI generated and most likely not tested.

More importantly, you sent all this work without properly organizing relevant patches into patchsets. This makes reviewing difficult and might cause multiple reviewers to address the same issue. Replying to the entire set is impossible and requires handling each patch independently, instead of applying or discarding the set. Maintainers also won't see the bigger picture of your work. Quite worrying.

This is on the verge of hostile patch: bomb us with so many contributions, we won't be able to handle them in efficient manner, like responding ONCE to ask you to slow down. Considering all this is untested and LLM generated, I have even more doubts whether this should be considered for review.

Please read kernel documentation BEFORE posting more work. It will explain you how to identify subsystems, how to organize your work per subsystem, how to document usage of LLM and how what you should not do if this was posted in a good faith.

Best regards,
Krzysztof