diff --git a/net/core/filter.c b/net/core/filter.c
index 7d6ceaa54d2147584e2033956c4740e4d0ef4af1..5cc9276f102383e1a10d0c88f2bd16e0638445ef 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2590,8 +2590,8 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start,
 			}
 			pop = 0;
 		} else if (pop >= sge->length - a) {
-			sge->length = a;
 			pop -= (sge->length - a);
+			sge->length = a;
 		}
 	}